As the title says is there a keyboard shortcut I can create to turn off laptop screen but keep sound on and not locking the session?
I already made a command keyboard shortcut that turns off screen But also cut off sound and locks session.
I would like to create this shortcut to only turn off screen but would like to listen to music with screen off.
I do not believe this can easily be done since the hardware power button is assigned a specific task that is essential.
It is possible, but probably not worth the risk.
What you can do is save the command as an autokey command:
Or as a Script
#!/bin/bash
xset dpms force off
Then set a keyboard shortcut to the /path/to/script
Make the script executable with (replace script-name' with the actual name of the file you saved):
gnome-terminal -- /bin/sh -c 'xset -display $DISPLAY dpms force off > /dev/null 2>&1'
Under Zorin Menu > Settings > Keyboard Shortcuts, I entered the above, then set the key combo as Super+L.
To set up a new keyboard shortcut, scroll all the way to the bottom of Keyboard Shortcuts and click the + button.
For your power button idea:
On my machine, the Power button is keycode 116, you can check what it is on your machine via: sudo showkey
Then you could do something like:
xmodmap -e 'keycode 116 = Control_L'
"Control_L" isn't correct, though... that's just something I pulled from Stack Exchange... you'll have to find the correct keycode. I'm not sure if keycode combinations such as Super+L can be used in that manner.
jesuslinux@T2310Z:~$ sudo showkey
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]
press any key (program terminates 10s after last keypress)...
keycode 28 release
keycode 116 press
keycode 116 release
Ctr+backslash:
jesuslinux@T2310Z:~$ sudo showkey
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]
press any key (program terminates 10s after last keypress)...
keycode 28 release
keycode 29 press
keycode 29 release
\keycode 41 press
keycode 41 release
I still recommend that a keyboard shortcut is sufficient for your needs.
Adding it to the Power Button can be tricky since your power button has an assigned task - To shutdown the computer and often, to restart.
It is difficult to add a third option when you have two options (Press - release) available. You risk replacing a function that you might need later (Such as an emergency hard reboot.)