Hidden Linux : Programming Multimedia Keyboards
I recently changed keyboards. The new one has a variety of specially labelled multimedia keys. I rarely use these things, preferring to program my own shortcuts that will work on any keyboard, but I also like a challenge.
On the new keyboard -- a Logitech Cordless Internet Pro -- the Mute and Volume keys work fine while the Email key starts KMail (I use Thunderbird). The other keys -- Media, Play/Pause, Favorites and WWW do nothing, so let's get them working...
All keys generate keycodes when pressed (and released) so we first need to see what codes the multimedia keys produce. The tool to use for this is xev -- the X event viewer. Install it, run it from a console window, and it'll display all keyboard and mouse events until you close the Event Test window. (Ubuntu users will find it's part of the x11-utils package.)
Here's what I get when releasing my non-functioning WWW key:
event, serial 31, synthetic NO, window 0x3800001,
root 0x188, subw 0x0, time 34924258, (169,-18), root:(175,11),
state 0x0, keycode 178 (keysym 0x1008ff2e, XF86WWW), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
The keycode is really all the information I need, but also notice the keysym (key symbol). Not every key produces a keysym.
If you want to display and edit keycode-to-keysym mappings, you'll need xmodmap. Install it, (it's part of the x11-xserver-utils package in Ubuntu), and run the following command:
xmodmap -pke > ~/.Xmodmap
This will write all current key mappings to the file .Xmodmap in your /home/username directory. The leading "." makes it a hidden file but you can still access it with a text editor.
Looking at the output file I find
|keycode 178 = XF86WWW|
which is exactly what xev told me. That's not terribly useful as the key doesn't work anyway, but if it did and I wanted to move its function to a different key, I could do so by simply reassigning the keysym.
To test xmodmap changes right away type;
|Tip: Killing CapsLock
I find the CapsLock key particularly useless. I mean, WHO WANTS TO SHOUT ALL THE TIME? Killing it is simple; just remove its keysym in .Xmodmap. Change
keycode 66 = Caps_Lock
keycode 66 =
and you'll never accidentally bump it on again!
What I really need is something to capture the keycode of the WWW key and associate a program with it. What I really need then is xbindkeys.
Install it, (it's just xbindkeys in Ubuntu), and run the following command to create a default file:
xbindkeys --defaults > ~/.xbindkeysrc
Now take a look at .xbindkeysrc in a text editor. You'll find several examples of the format used at the top of the file. In my case I merely added this to the bottom of the file and saved it.
#Start Firefox when the WWW key is pressed
To test your settings interactively, type
(Use Ctrl+C to quit.)
Note that the default examples in .xbindkeysrc reprogram the Ctrl+F, Ctrl+Shift+Q and Ctrl+MiddleMouseButton settings. You might want to comment out those out before you proceed!
Auto-start the new settings
Once you've completed and tested all your multimedia key modifications, you can start them automatically each time you boot by adding the following two lines to the bottom of the .bashrc file in your /home/username directory:
<--Previous Hidden Linux Next Hidden Linux -->