Multimedia keys in X


Forum: DSL Tips and Tricks
Topic: Multimedia keys in X
started by: mikshaw

Posted by mikshaw on Aug. 17 2006,18:32
Using Multimedia Keys In DSL (in X)

DISCLAIMER: I can't say that this will work completely, or at all, for the
random user. I can say only that this worked for me using the default 'us'
keymap with a Logitech® Access™ keyboard.

INTRODUCTION: My keyboard has multimedia keys, which I've used in other distros
without much trouble due to the fact that scancodes for these keys had already
been implemented, so the xev program sees the keycodes which can then be used
by xmodmap. In DSL xev registers nothing when I press these keys, so apparently
the kernel does not assign keycodes to them. If you receive no events from xev
when attempting to get the keycodes for your multimedia keys, this tutorial may
help (or at the very least point you in a useful direction).

STEP 1: Find out what codes are sent by your keyboard's "special" keys.
       Fortunately, for many people, this task has been made very easy by a
       kind soul (Andries Brouwer) who posted his efforts online:
       < http://homepages.cwi.nl/~aeb/linux/kbd/scancodes.html >
       If your keyboard is not listed, you can get the scancodes yourself.
       First, exit the X server. This next command won't run in X.
       Use the command 'showkey -s' to display the scancodes you'll need for
       creating keycodes. You will be asked to press one or more keys, after
       which the scancodes for the pressed key(s) will be displayed. Showkey
       will print 2 pairs of numbers.  The first number in each pair is an
       escape (0xe0), and the second are the press and release sequences sent
       by the keyboard. Depending on how quickly you release, you may get two
       lines beginning with 0xe0, or it may be split onto two lines.
       For example, if showkey prints "0xe0 0x12 0xe0 0x92" the number for a
       press event is 0xe0 0x12, which is shortened to e012 for the next step.

STEP 2: Use the command 'setkeycodes <scancode> <keycode>' to create a keycode.
       The scancode is the 4-char code mentioned above (e012) and the keycode is
       a number between 1-127 (in DSL).  You can see which keycodes are unused
       by running the command 'dumpkeys | grep =$'.  You may find that you have
       more keys to map than are listed by this command.  At this time I'm not
       sure what issues there are in setting a keycode that is already in use,
       but that will hopefully be discovered and included here later.
       One thing to keep in mind is that X and the kernel do not use the same
       keycodes.  Assigning the code with setkeycodes allows the kernel to see
       the key, and it is then available to X, but you will still need to find
       out what keycode is being used by X before using the keys in fluxbox or
       other application that relies on keysyms.
       
STEP 3: Now you can return to X. As I mentioned above, X sees a different code
       than the console does, so you'll need to find out what that X code is.
       For that we use the xev program. Open an X terminal and run 'xev'. When
       xev has focus (you may need to click the xev window), all X events will
       be read and information about the events will be printed to the xterm.
       Near the bottom of the info, xev shows the keycode and if there is an
       associated keysym it will display that as well.  Since we are working
       with new keys, there will not be a keysym listed (shows "NoSymbol").
       This is what we want to create so the keys can be mapped in Fluxbox.

STEP 4: Now that we know what keycode X is seeing, we can use xmodmap to assign
       a keysym to that keycode.  The syntax is
           xmodmap -e "keycode <keycode> = <keysym>"
       You can get a list of useable keysyms by running the command
           grep ^XF86 /usr/X11R6/lib/X11/XKeysymDB
       At this point, xev should list a keysym which can be added to your
       ~/.fluxbox/keys file.  The next step is making it persistent.

STEP 5: In order for this to happen automatically when you boot, the commands
       should be added to your startup scripts.  The setkeycodes commands are
       run by root, so they should be added to /opt/bootlocal.sh, one command
       for each scancode. You could instead put them in ~/.bash_profile, with
       "sudo" before each command. The xmodmap commands can be put in a file,
       such as ~/.Xmodmap (leave out the "xmodmap -e" in this case), and then
       run from ~/.xinitrc with the command 'xmodmap $HOME/.Xmodmap'.
       Now you should be done. To make this task easier it might be useful to
       keep a list of your keyboard's scancodes, as well as the keycodes and
       keysyms that you set, so you won't need to refer to several files and
       applications if this needs to be repeated in the future.

==========
EDITS:  Added URL of a useful page listing keyboard-specific scan codes.
       Cleared up a little bit of the setkeycodes confusion.

TODO:   Add some info on using these keys in the linux console (loadkeys?)

Posted by ^thehatsrule^ on Aug. 17 2006,18:40
This sounds similar to what I did for my mm k/b - only exception is that I looked up which key scancodes corresponded to which buttons first :)
The only thing I could not find out was how to control my extra LED yet - would you know anything on that?

Nice guide!

Posted by mikshaw on Aug. 17 2006,20:34
Quote (^thehatsrule^ @ Aug. 17 2006,14:40)
I looked up which key scancodes corresponded to which buttons first :)

I'm not sure what you mean...did you google a list for your specific keyboard?
EDIT: found it:
< http://www.win.tue.nl/~aeb/linux/kbd/scancodes-6.html >
That's sweet =o)

I don't know anything about leds, sorry.  I have one that I don't know what it's for, and that stupid "f lock" key is always off by default...which i think is pretty useless.

Posted by mikshaw on Nov. 14 2006,02:32
To underline the original disclaimer, I recently got fed up with my logitech keyboard, since even after thorough cleaning the keys would stick and make touch typing impossible (and the f-lock button is seriously stupid).  So I replaced the keyboard with a HP something or other, and the above steps did not work for its multimedia keys.
So Now I'm typing with a Dell QuietKey with no special buttons...I remapped all of my actions to Windows key combos =op

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.