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.
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.
- 23,201
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,775
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

