6

I'd like to have certain keys (mainly media keys) reach my windowmanager even if my lockscreen is active. This way, I could control my media player even when my screen is locked.

As far as I can see, this is probably only possible if the screen locker supports this: Once the screen locker has grabbed the keyboard pointer away from the root window, there seems to be no way of receiving keypress events.

Does anyone know any screen lockers supporting such a thing? Or any other way of listening to keypresses while a lockscreen is active?

Thank a lot,

Lukas

1

I figured something out: listening for raw keypresses is possible even when the keyboard focus is grabbed away by a screen locker. The downside is that with raw keypresses, you have to manually track the state of the modifier keys, but that seems to work pretty well.

I built a small hotkey daemon based on this idea which allows to execute commands even while the screen is locked. If anyone is interested, you can find it here: https://github.com/tinloaf/lhkd

0

If your media keys send ACPI events, you could use acpid to act on them.

Unfortunately, it requires global config changes (instead of per-user), and it might be tricky to communicate the events to your X11 applications.

You can see what ACPI events, if any, are sent by your media keys by running acpi_listen and then pressing those keys. For example, this appears in acpi_listen output when I press "brightness up" key on my laptop:

video/brightnessup BRTUP 00000086 00000000

If your keys do send ACPI events, you can configure acpid to run a command when they're pressed. The relevant configuration files are usually found in /etc/acpi/events/. They can have any name, as long as they're in the right directory. They look like this:

event=^video/brightness(up|down) .*[^K]$
action=/etc/acpi/backlight-handler.sh %e

The first line constains event= followed by a regex to match the ACPI events. If an event matches the regex, the command specified in the second lin (after action=) is executed. The %e is expanded to the event line. In this case, it's used to pass the event as commandline arguments to the script.

There's also a nice article about acpid on Arch Wiki: https://wiki.archlinux.org/index.php/Acpid

The next step would be to figure out how to control your media player from a script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.