I have used Automatically locking screen without shutting it off and other threads but ultimately it locks the screen, which is not what i am asking.
-
1Why are you posting a new question from a new account? Please edit [your older question](https://askubuntu.com/questions/1110208/is-it-possible-to-turn-off-display-with-power-button-without-locking-screen-li) and add details. – pomsky Jan 18 '19 at 08:16
-
sorry about that. but i can't seems to access that a/c. I tried like for an hour and i gave up. Please help me solve the question – Pranav Jan 18 '19 at 08:18
-
Through my original a/c, i can't ask question anymore. So i have almost created like 3 a/c to get my answer. Keeping track of them is a bit annoying. – Pranav Jan 18 '19 at 08:20
-
u asked me, "gsettings get org.gnome.settings-daemon.plugins.power power-button-action" the output is "suspend". – Pranav Jan 18 '19 at 08:21
-
u asked me, "gsettings range org.gnome.settings-daemon.plugins.power power-button-action", the output is "enum 'nothing' 'suspend' 'hibernate' 'interactive' " – Pranav Jan 18 '19 at 08:22
-
What happens if you run `gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'interactive'` and then press the power button? – pomsky Jan 18 '19 at 08:23
-
well, it give me a pop-up option to whether "Power Off, Restart and Cancel" – Pranav Jan 18 '19 at 08:25
-
Okay, so that didn't help. You may want to run `gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'suspend'` to revert to the old setting (i.e. power button suspends the system). – pomsky Jan 18 '19 at 08:27
-
That locks the screen, i don't want that. I just want to turn off the display. – Pranav Jan 18 '19 at 08:30
-
I understand, as said this command is to undo the effect of the previous command I suggested. – pomsky Jan 18 '19 at 08:43
-
As as post suggest, i repeat, "Is it possbile to make power button to turn off display only or not? No screen locks like in Windows" – Pranav Jan 18 '19 at 08:50
-
Because many user say, it is possible. So – Pranav Jan 18 '19 at 08:51
-
**Yes, I hear you loud and clear**. I suggested the command `gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'suspend'` just to **undo the effect** of the command `gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'interactive'` that **you ran before** following my previous suggestion. **This is not intended to solve your issue**. – pomsky Jan 18 '19 at 08:52
-
u r putting me in loop again and again. Give me a solid answer. – Pranav Jan 18 '19 at 08:55
-
2Please don't demand for an answer in that way. In case you're mistaken Ask Ubuntu is *not* a free Ubuntu tech support, we're just a community of (mostly) average Ubuntu users. And also I failed to realise how I'm putting you *in loop again and again*. I suggested something, which didn't work. So I suggested the way to undo the effect of my previous suggestion before completely disengaging from this question. Thank you, have a good day. – pomsky Jan 18 '19 at 09:05
-
ok, thanks anyway pomsky. (Let me know, if u know) – Pranav Jan 18 '19 at 09:14
-
Sure thing, if I manage to find anything relevant, I'll certainly let you know. – pomsky Jan 18 '19 at 09:16
3 Answers
Workaround:
It is possible, if the Menu key could be sacrificed.
First set a custom shortcut for Menu key as xset dpms force off
This means, when you press Menu key, xset dpms force off command will run and turn off the display.
Now the trick is to map this Menu key to PowerOff key with xmodmap
run xmodmap -pk | grep PowerOff to know the keycode for PowerOff button.
Example:
pratap@i7-6550U:~$ xmodmap -pk | grep PowerOff
124 0x1008ff2a (XF86PowerOff) 0x0000 (NoSymbol) 0x1008ff2a (XF86PowerOff) 0x0000 (NoSymbol) 0x1008ff2a (XF86PowerOff)
pratap@i7-6550U:~$
In my case 124 is the Key code for PowerOff Button with my Keyboard.
now run the below command in terminal to map the PowerOff key to Menu key.
xmodmap -e "keycode 124 = Menu"
at this stage you literally have two Menu Keys in your keyboard which will run the command xset dpms force off.
Now you can check, if you press Menu Key or PowerOff key the display will be turned off.
the command xmodmap -e "keycode 124 = Menu" will not survive logout or reboot.
So, Create a startup preferences with command xmodmap -e "keycode 124 = Menu" like below and then Reboot.
When ever you want to remove this mapping, just delete the entry from startup preferences.
- 21,989
- 8
- 59
- 121
-
That seems very promising and real but when i at the time of choosing a Keyboard, "Power button" doesn't respond at all. That is, it ain't get selected or anything like that. – Pranav Jan 19 '19 at 03:24
-
Can u explain it in minor details? "snap left ?" (I do have dconf edit though). – Pranav Jan 19 '19 at 04:27
-
-
Power button did "split on right". After that i managed to edit put "Power button" on custom shortkey which was designed to "turn off the screen". After that i use above ( gsettings set org.gnome.settings-daemon.plugins.power button-power 'nothing' && gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'nothing' ). Now even when everything alright, power button do nothing. – Pranav Jan 19 '19 at 06:30
-
Can u tell me what u have used in Power setting. What have u used in this menu called "When the power button is pressed", have u selected "Suspend, or 0 seconds, or Power Off, or Hibernate, or Nothing" ? – Pranav Jan 19 '19 at 06:50
-
@Prabeshbhattarai I followed his instruction and it worked for me. I selected 'Do nothing' for 'when power button is pressed' – Kenivia Dec 25 '19 at 11:54
-
1I Didn't use Menu button as after looking through the keymap, I found some keys for Japanese keyboard that I would imagine most of us have never used. For example, I rebinded the power button to 'Katakana' and it worked perfectly, without sacrificing any functionalities. – Kenivia Dec 25 '19 at 11:56
-
@PRATAP Great Answer by the way, appreciate your effort! Really helped me out. – Kenivia Dec 25 '19 at 11:56
-
BTW, to undo the `xmodmap` command (i.e. other than rebooting) you can run `xmodmap -e "keycode 124 = XF86PowerOff"` – Guss Sep 04 '20 at 14:10
You can set the power management to turn off the screen when you press the power button, but unless automatic locking is set to "Off" (in "Privacy" setting), the system will lock when you turn off the screen.
Unfortunately there's no way in Ubuntu (based on GNOME) to change that behavior - either no lock at all, or lock when the screen turns off.
Other desktop environment, such as KDE Plasma, XFCE or Budgie might offer more refined settings.
- 3,435
- 3
- 33
- 42
This is really simple
first go to settings > power >and set the power button to do nothing
next go to settings > keyboard > shortcuts > custom
add the custom command xset dpms force off and set its accelerator as power+cntr
hope this helped
i tried this in elementry os hera but scince elementry is based on ubuntu it should work just as well

