Etusivu | Tietokonejutut index

Configuring multimedia keys on X

This quide shows how I have configured my multimedia keys on my laptop (Acer Travelmate 4670). You can bind any keys the same way. Also, this may not be the only way to do this, but this is fairly easy and works well. If you are after a GUI way to do this, you're in a wrong place.

1. Setting keycodes for keycodeless keys

This step is not always necessary as the keys may already have keycodes assigned. If that is the case, you can skip to step two. If pressing a key only produces error messages to your root console (in most cases press Control+alt+F1 to see it), you need to apply this step.

The error messages look something like this:
atkbd.c: Unknown key pressed (translated set 2, code 0x9e on isa0060/serio0).
atkbd.c: Use 'setkeycodes e01e <keycode>' to make it known.

The message is pretty straightforward, you need to apply that command to all those 'missing' keys. (You can also get the scancodes with showkey. It's probably a good idea to see the manpage.)

I'm not sure if there's a better way to do this (actually I'm pretty sure there is), but I made a script that assigns those scancodes to keycodes on boot. I've set my keycodes by converting the scancode from hex to decimal and adding 128.

I put a line in /etc/rc.local pointing to my script to tell it to be run on every boot. I put it there instead of X starup scripts so the keys won't produce error codes when I'm not using X. The script looks simply like this:

# This script sets keycodes for Acer TravelMate 4670's non-standard keys
# and is called from /etc/rc.local . Remember to update the rc.local file
# you choose to remove this file.
setkeycodes e026 210 e027 211 e029 213 e071 185 e06e 182 e033 225 e034 224 e055 157 e056 158 e057 159 e058 160
exit 0

2. Giving names to keycodes

Now you usually bind keycodes to keysyms with xmodmap. It's not necessary as xbindkeys can also use keycodes instead of keysyms. In Debian you can find a list of available keysyms in /usr/share/X11/XKeysymDB . It may be in somewhere else in your system.

You can see keycodes in X with xev (or with showkey in terminal session). Then you can make your ~/.Xmodmap file. Seeing xmodmap's manpage is recommended if you don't know what to do. After you've written the ~/.Xmodmap xmodmap has to be run when you start X. I've put a following line in my ~/.Xsession
xmodmap ~/Xmodmap &

3. Binding the keys to do something

Now the last step is to bind your keys to do something when pressed. This can be done either with window manager's configuration or with xbindkeys. I've used xbindkeys as it's not dependant of any window manager.

Xbindkeys's bindings are done by ~/.xbindkeysrc . You can get a nice sample .xbindkeysrc by running xbindkeys -defaults > ~/.xbindkeysrc . Note: If you specify a keysym in xbindkeys that has no key bound to it, xbindkeys hangs and you won't be able to use your keyboard until you stop xbindkeys. This may come handy in troubleshooting.

After you've set your .xbindkeysrc, you can apply your bindings by running xbindkeys. I've put a line in my .Xsession telling xbindkeys to be run after the xmodmap.

Valid XHTML 1.0!