On MacOS, the F6 key toggles Do Not Disturb mode instead of going to sleep, which I personally find more useful.

Here’s what worked for me on GNOME:

run

sudo nano /usr/lib/systemd/logind.conf

uncomment HandleSuspendKey and change its value to ignore

HandleSuspendKey=ignore

save, copy it to the location below so it persists across updates:

sudo cp /usr/lib/systemd/logind.conf /etc/systemd/logind.conf

open GNOME’s Keyboard Shortcuts GUI, create a shortcut called Do Not Sleep, map it to the Sleep key (F6) and to the command below:

sh -c 'gsettings set org.gnome.desktop.notifications show-banners $(if [ "$(gsettings get org.gnome.desktop.notifications show-banners)" = "true" ]; then echo "false"; else echo "true"; fi)'