8th May 2008
Note, that under Gnome I only had to use a single system-wide utility to bind volume buttons to volume control. Under KDE things were a tad tougher.
First, you may want to look for kmilo (if you don’t have it yet). It has several plugins e.g. for ThinkPad and Vaio laptops, as well as “generic” plugin. I didn’t try this solution, though.
If you need more than kmilo can offer: keyTouch could help. keyTouch should be good also for non-laptop multimedia keyboards. However, this also wasn’t the solution I used.
If you want to know how to map your special keys to functions yourself – then read on.
(Main source used: mapping unsupported keys with xmodmap – it’s easy and clear, but didn’t work exactly as expected for me).
Let’s go step-by-step. (Note: I’m on Debian Etch on LG LM70 Express laptop.)
- run this command (copy and paste – should be single line) in the Konsole or whatever terminal window you have open; you don’t need to be root to run this command
- xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
- xev window will appear. Put mouse cursor over that window, and press the buttons you need to enable under Linux, memorizing/writing down the codes you get. In my example, I pressed “vol. -”, “vol. +”, and “mute” buttons of the laptop, and observed the following output in the console window:
Those numbers on the left are keycodes, and the NoSymbol tells us that none of keysyms was bound to those keycodes
- now we need to create keycode-keysym bindings. For that, open with your favourite text editor (such as pico, nano, vi, kate, mcedit etc) the file ~/.Xmodmap (e.g. nano ~/.Xmodmap in the console)
- now you need to decide how to bind those special keys. For my case, the X window system has reserved key symbol names, namely X86AudioLowerVolume, X86AudioRaiseVolume, and X86AudioMute. For your case, you may need to lookup if there’s a pre-defined name for the functionality you are enabling – it would be best if there is such a name. Otherwise, you can use such keys as F13, F14, F15 etc (which are not physically present on the keyboard)
- write the bindings to the Xmodmap file. Format is simple, as in my case:
Keycode 160 = XF86AudioMute
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
- to apply the change, save Xmodmap file, exit the editor, and then from the console execute xmodmap ~/.Xmodmap. Now the bound keys must be visible to KDE’s “global shortcuts” (and any other “keyboard shortcut input” fields). To check, I right-clicked KMix, “Show mixer window”, “Configure global shortcuts”, and then just assigned respective keys to volume control options. It worked for me. Later I disabled those shortcuts, and everything still works fine (might be because of the installed kmilo, but I didn’t check)
- on Debian Etch, when starting KDE from kdm, the .Xmodmap file isn’t automatically applied at KDE startup. This can be easily fixed by creating the xmodmap.sh file in the ~/.kde/Autostart/ directory, with a single line: /usr/bin/xmodmap $HOME/.Xmodmap. Dont forget to chmod u+x xmodmap.sh. The xmodmap.sh script will bind codes to symbols at each KDE start. (Alternatively, the same script could be put into ~/.kde/env/, but according to startkde man-page, that folder is used for scripts which set KDE-wide variables, whereas we only run a command and do not assign any variables. Also, I wouldn’t recommend putting xmodmap invocation into .bashrc or .bash_profile – those are executed whenever you login, but presented model of xmodmap usage seems to have sense for KDE only.)
This is it.
For the method of using DCOP in KDE for hotkeys please see my primary source, which has a simple but clear KMix DCOP example.