54

I have a "power button" on my keyboard that enables standby or hibernate. I can't find the mapping of this key anywhere in "sytem settings>Keyboard", "system>power management", "compiz config> or similar (where I could find it before unity). How can I disable (not remap) this button?

I do not want to disable hibernate/sleep altogether, it's simply this key that gets pressed a lot by accident and it's getting quite annoying.

Braiam
  • 67,791
  • 32
  • 179
  • 269
KillianDS
  • 886
  • 8
    Try a chisel and a pair of pliers. – Mike Scott Mar 23 '12 at 10:14
  • 1
    I was asking about this on the forum and annoyingly still have no answer. The GUI setting disappeared with the move to GTK3. – edm Mar 23 '12 at 12:05
  • Remove the key from keyboard with a pencil. (Don't do that, just a joke until final answer arrises...=) But I made it in some strange work situations... Just put the key back in when you done! Don't break keyboards! – H_7 Mar 23 '12 at 12:10
  • I just disassembled the keyboard and removed the button. Problem solved. – mchid Mar 26 '22 at 02:39

5 Answers5

55

Disable the suspend button in your system

gsettings set org.gnome.settings-daemon.plugins.power button-suspend "nothing"

Revert to the default value

gsettings set org.gnome.settings-daemon.plugins.power button-suspend "suspend"

Disable the sleep button in your system

gsettings set org.gnome.settings-daemon.plugins.power button-sleep "nothing"

Revert to the default value

gsettings set org.gnome.settings-daemon.plugins.power button-sleep "hibernate"

Disable the hibernate button in your system

gsettings set org.gnome.settings-daemon.plugins.power button-hibernate "nothing"

Revert to the default value

gsettings set org.gnome.settings-daemon.plugins.power button-hibernate "hibernate"

Settings those options above does not disable the functions in your system, you can still use the cog wheel menu to hibernate / suspend, this only disables keyboard and other buttons you might have in your computer.

Bruno Pereira
  • 73,643
  • 3
    I filed a bug against ubuntu gnome-control-center keyboard shortcuts GUI. It should manage these buttons like other keyboard buttons: https://bugs.launchpad.net/ubuntu/+source/gnome-control-center/+bug/1079190 – Stephen Ostermiller Nov 15 '12 at 14:02
  • 6
    Didn't work for me on 18.04. I set all 3 to "interactive", but pushing the "sleep" button on the keyboard just locks me out immediately. – MWB Jan 29 '19 at 05:18
  • Wouldn't it be easier to just use reset for reverting stuff? – d4Rk Sep 14 '19 at 11:02
  • I'm looking into this on ubuntu 18. It looks like it would be handled by systemd-logind, except that gsd-media-keys from gnome-settings-daemon is taking over control. – fuzzyTew Apr 27 '20 at 15:04
  • 1
    Can confirm, sleep button still pushes me out of my PC. – Tachytaenius Aug 20 '21 at 14:36
  • Did not work on Ubuntu 20.04 – Antonio Sesto Mar 18 '22 at 12:35
38

Dconf Editor is the recommend replacment to gconf editor for Unity. You can get dconf in the software center or by typing sudo apt-get install dconf-tools in the terminal.

With Dconf editor, navigate to org gnome settings-daemon plugins power. There you can change what the sleep button does, as well as many other buttons on your keyboard.

enter image description here

James
  • 17,106
  • 5
  • 24
  • 38
12

Since Ubuntu 18.04, Bruno Pereira's answer doesn't seem to work anymore.

To disable any key, you will need to get its code:

xmodmap -pk | grep -i sleep

For me, the sleep button has the code 150 as you can see:

    150     0x1008ff2f (XF86Sleep)  0x0000 (NoSymbol)   0x1008ff2f (XF86Sleep)  0x0000 (NoSymbol)   0x1008ff2f (XF86Sleep)  0x1008ff2f (XF86Sleep)

Once you have the key code, you mainly have two ways to automatically disable it.

Disable for some users

If you just need to disable it for one or many users, you can add this command to the Startup Applications, assuming the key code of your sleep button is 150:

xmodmap -e 'keycode 150='

If the user logs off, the button will be enabled again. If you want to keep it disabled, try the other method instead.

Disable for every users

The button will be disabled after each booting. You will need the administrator privileges for this. Edit this file:

sudo gedit /usr/share/X11/xkb/keycodes/evdev

The line we will have to edit looks like <SOMETHING> = <your_keycode>. Once you found it, add // at the beginning to comment it. In my case, I had to change this:

    <I150> = 150;   // #define KEY_SLEEP               142

Into this:

//  <I150> = 150;   // #define KEY_SLEEP               142

Note: With both methods, the button will still be enabled for few seconds when booting or logging in.

Sources:

Pablo Bianchi
  • 15,657
Zatigem
  • 478
  • 1
    Thank you. To apply this change, Alt+F2, type the single letter r then Enter, it will restart gnome GUI without killing any app. Drawback: you can't use the key anymore, like in a shortcut, direct or with a modifier. – lolesque Jul 13 '22 at 11:14
5

Have you also tried this one?

gsettings set org.gnome.settings-daemon.plugins.power button-suspend "nothing"

I did all 3 from the linked-to question and it fixed this for me (x86 on 12.04).

EDIT: Here's a single command that does all 3:

for x in button-{suspend,sleep,hibernate}; do 
  gsettings set org.gnome.settings-daemon.plugins.power $x "nothing";
done
  • Thank You very much - it has solved my problem of unwanted suspends (the key is on my keyboard direct next to calculator key) ===> I use now gsettings set org.gnome.settings-daemon.plugins.power button-suspend "interactive" – kapetr Mar 12 '13 at 08:48
  • ... but if I remember correct: I had try in previous set button-suspend too (just forget it list in Q) but id does not help too. But now (maybe some update?) does :-) and thanks your reply i have try it again and IT WORKS! End good all good :-) – kapetr Mar 12 '13 at 09:33
  • ooh, "interactive" sounds potentially useful -- though I think I'll stick with "nothing" for now. I looked up this question because I was sitting on the floor with my tvputer and my 14-month-old daughter seemed to enjoy pushing the silver Moon button on the corner of my keyboard. And all the other buttons, which made retyping my password a bit of a challenge. – Ed Brannin Mar 13 '13 at 18:24
0

None of this worked for me, I don't have Gnome I use OpenBox, as most of you will know is very "bare bones" with a Ubuntu 18.04 kernel running.

This solution should work for most systems.

  1. Go to this path: /etc/systemd

  2. Edit as root: logind.config

  3. ADD or uncomment these lines;

    HandlePowerKey=ignore
    HandleSuspendKey=ignore
    HandleHibernateKey=ignore
    

Why did I do this, this cheap goofy keyboard has "Power", "Sleep", "Wake Up" following the F1-F12 keys, when I go to press F12 I hit power and the system powers off and my work is lost!

Pablo Bianchi
  • 15,657
Wendy
  • 1