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.
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.
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:
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.
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.
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