Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to allow a keyboard's volume keys to continue working when your desktop is locked? Currently, the default behavior disables all special-function keys until the desktop's unlocked. I like to use my PC as a music player and leave it locked when I'm not directly at the console, but I still want to let people to control the volume if a song's too loud.

share|improve this question
    
+1! I bet that a side effect of this (if it is possible) is to not re-awaken the sleeping display, which is something I've wondered about before. –  David Oneill Apr 17 '12 at 18:05
    
I'd like to have this functionality too. Not only for volume, but also for the music control keys (play, pause;next;previous). –  jP_wanN Apr 18 '12 at 20:46
    
As an aside, as I was upgrading I turned my screen down to the lowest setting. Halfway through the install I couldn't turn it back up. Made for an interesting experience.. –  JavaNut13 May 23 '12 at 10:10
    
I wonder if the media keys could be made into some kind of fake LIRC device, pretending to be a remote control ... At least conceptually it makes sense, right? –  taneli May 24 '12 at 12:04

3 Answers 3

up vote 4 down vote accepted

Somewhat of a shameful plug, but since there didn't seem to be any existing solution, and since the task seemed relatively straight-forward, I wrote a simple Python daemon to fix the problem. It uses the python-xlib API to capture system-wide key presses and then runs custom shell commands. It assumes a basic Debian/Ubuntu setup, but would probably work on most Linux systems with a few tweaks.

For my case, the volume up/down keys map to the code 122/123, so the corresponding commands to lower or raise volume only when the desktop is locked are:

gnome-screensaver-command -q | grep "is active" && bash -c '/usr/bin/pactl -- set-sink-volume `pacmd list-sinks | grep -P -o "(?<=\* index: )[0-9]+"` -10%'
gnome-screensaver-command -q | grep "is active" && bash -c '/usr/bin/pactl -- set-sink-volume `pacmd list-sinks | grep -P -o "(?<=\* index: )[0-9]+"` +10%'

Admittedly, that's a bit verbose. The second grep is to find the active sound interface on systems that might have several (e.g. my laptop has a Master and Headphone interface, allowing these commands to control either).

share|improve this answer

This problem needs to be solved on a general level. A workaround is no solution. With older Ubuntu versions (from 2010 or so) the volume hotkey still worked at a locked screen.

I consider this a bug, especially since other hotkeys still work at a locked screen, like the WiFi key, screen brightness and sleep. For security reasons, I'd rather see the WiFi and sleep hotkeys locked, but not locking hotkeys at all - of course - is most convenient. Best choice is to have an option for this at "System Settings/Brightness & Lock" or in gconf.

share|improve this answer

This kinda worked for me but after the screensaver is ended all the sound was dead. Then I had to figure out how to restart the pulseaudio server to get any sound working again.

I'm still running Lucid 10.04LTS with 2.6.32-58-generic

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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