Command Shortcut to turn off screen XFCE

Hello,

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.

Thanks

Yes, you can use

xset dpms force off

To re-activate the screen, press any key or wiggle the mouse.

Thank you!

Is it possible to assign this to the power button?
One press on the power button and turn of screen?

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

chmod +x script-name.sh

1 Like

Here's how I did it:

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.

Super key is keycode 125,  L  key is keycode 38.

I have the command:

xset dpms force off

With keyboard combo of:

ctrl+backslash

My power button is also 116

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

How would I combine that to assume the power key?

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

That's a good point.

On Win10 I could do that on the power management on the option to select what the power button do and select turn off screen.

It would be a nice option to have on future updates on Zorin.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.