Multimedia/Internet Keyboards in GNU/Linux

Articles | General Interest

As the resident geek, I sometimes help new users making
transition to GNU/Linux from other OS's. Over the years, I'd ask
anyone who installed Gnu/Linux about which hardware devices that
didn't work for them, most often it is 'Multimedia/Internet
keyboards'. In this article, we'll configure one such keyboard
using the Hotkeys program.

Anthony Wong's Hotkeys is written to handle all those special
keys provided by the Multimedia/Internet keyboards and launch
programs associated with them.Though there are numerous ways to
configure these keyboards in Gnu/Linux, Hotkeys is far easier to
configure and its osd (on-screen display) is very similar to those
available on other OS's.

You can visit Hotkeys
site to download the latest version of the program as "http://ypwong.org/hotkeys/hotkeys-latest.tar.gz">tarball or
"http://ypwong.org/hotkeys/0.5.7.1/hotkeys_0.5.7.1_i386.deb">deb
package.

The installation on Debian machine can be done using the
apt-get.

  $ apt-get install hotkeys

Configuration

Hotkeys starts a daemon,usually started with xinit process,it
uses a global configuration file /etc/hotkeys.conf and users can
store their configuration in $HOME/.hotkeysrc.

The hotkeys.conf file is well commented, should not present any
problems to new users.Its contains can be summed up as.

  • Device Settings

    Keyboard Type  (kbd="")
    CD Drive (CDROM="")

    The supported keyboards can be checked with 'hotkeys -l'
    command.

  • Key Behavior

    Tag = 'command' (Play = "xmms --play-pause")
    

    The complete list of tags can be found in
    /usr/share/doc/hotkeys/sample.xml file.The users can also create
    their own custom tags.

  • On-Screen Display Properties

    Font            (osd_font="")
    Color (osd_color="")
    Position (osd_position="")

A sample /etc/hotkeys.conf file.

############################################################
# Global configuration for hotkeys #
############################################################

# These are the default values.
# A line starting with # is a comment.

### Specify the default keyboard (without the .def extension) so you
### don't need to specify -t every time
Kbd=hp5181
CDROM=/dev/cdrom # use 'none' if don't have a CDROM Drive

PrevTrack=xmms --rew
Play=xmms --play-pause
Stop=xmms --stop
Pause=xmms --pause
NextTrack=xmms --fwd
Rewind=

WebBrowser=mozilla
Email=mozilla -mail
Calculator=xcalc
FileManager=gmc
MyComputer=gmc
MyDocuments=gmc
Favorites=gnome-moz-remote --remote=openBookmarks
Transfer=gtp
Record=grecord
Shell=xterm -rv
ScreenSaver=xscreensaver-command -activate
NewsReader=mozilla -news
Communities=mozilla -remote 'openURL(http://slashdot.org)'
Search=mozilla -remote 'openURL(http://google.com)'
Idea=mozilla -remote 'openURL(http://sourceforge.net)'
Shopping=mozilla -remote 'openURL(http://thinkgeek.com)'
Go=mozilla -remote 'openURL(http://linux.com)'
Print=lpr
Rotate=

osd_font=-arphic-ar pl kaitim big5-bold-i-normal--0-250-0-0-c-0-*-*
### For the color, you can either use the strings in /etc/X11/rgb.txt,
### or use the RGB syntax #RRGGBB, e.g. ##A086FF
osd_color=LawnGreen
osd_timeout=3
### osd_position is either 'top' or 'bottom'
osd_position=bottom
osd_offset=25

Configure a new Multimedia/Internet keyboard

The Hotkeys program is still under development, you may not find
your keyboard in the default list. To configure your keyboard, find
out the keycodes of all the special keys on your keyboard.

Use the xev program to capture the keycodes and save it to
file.Move your cursor over to the white square on the xev window and press the
special keys in a sequence. Do remember the sequence, later you may have trouble in assigning keycodes.

  $ xev 2>&1 >mykeys

Search the file for the keycodes.

  $ grep 'keycode' mykeys | cut -d ' ' -f7,8 >mykeycodes

Check the file to see the keycodes.

   $ cat mykeycodes

keycode 223
keycode 166
keycode 151
keycode 232
keycode 159
keycode 153
keycode 144
keycode 165
keycode 158
keycode 146
keycode 178
keycode 150
keycode 148
keycode 149
keycode 173
keycode 164
keycode 163
keycode 162
keycode 161
keycode 152
keycode 160
keycode 174
keycode 176
keycode 64

Hotkeys uses XML to define keycodes and their
functionality.These are stored as ' .def ' files in
/usr/share/hotkeys directory. Let's use the sample.xml file provided
by the hotkeys to build a custom keyboard definition file.

  $cp /usr/share/doc/hotkeys/sample.xml /usr/share/hotkeys/custom.def

The hotkeys support various pre-defined 'tags' like Sleep,
Search, Shopping and various CD/DVD player controls(See
/usr/share/doc/hotkeys/sample.xml).Each 'tag' has a behavior
assigned, Sleep uses APM to turn your computer into hibernation.Many
other special function keys can also be configured.

For example the half-moon key on my keyboard is configured using
'Sleep' tag.

<Sleep        keycode="223"/>

And un-defined Shortcut key is set with.

<userdef keycode="232" command="xterm">Xterm</userdef>

Here is how the custom.def appears with the above examples.

<?xml version="1.0"?>
<definition>
<config model="My custom keyboard">

<!-- Support Tags functions -->
<Sleep keycode="223"/> <!-- half-moon key -->

<!-- User define functions -->
<userdef keycode="232" command="xterm">Xterm</userdef>
</config>

<contributor>
<name>your-name</name>
<email>your-email</email>
</contributor>
<definition>

Now test the custom.def by using it as your keyboard type.

        $ hotkeys -t custom

A lot more keys can be set using the same custom.def file, a
little effort pays off well. If you have configured your new
Multimedia/Internet keyboard using hotkeys, do take time to send your '.def ' to the project developers, it may help many other users with same kind of
keyboard.

Latest issues

For related and latest articles visit us at Grmtech technical writing team

Web Resources

Hotkeys Help Forum

"http://sourceforge.net/forum/forum.php?forum_id=91461">http://sourceforge.net/forum/forum.php?forum_id=91461

Hotkeys Project

"http://sourceforge.net/project/hotkeys/">http://sourceforge.net/project/hotkeys/

Rakesh 'arky' Ambati is a Red Hat Certified Engineer he
spends time working on technical writing for "http://www.grmtech.com/">GrmTech and interested
in Free Software movement, also coordinating local Free
Software activities.He lives in Bangalore,India.

unknown keys in kernel 2.6.x (long post)

The keyboard handling was rewritten in 2.6.x and it is not complete.
On my logitech keyboard, I get the following console message for some of the multimedia keys:

Use 'setkeycodes e012 ' to make it known.

And of course, X does not see any events for those keys.
The tool 'setkeycodes' can be used to define a 'keycode' for this key event but the problem of course is to find which 'keycode' to use.

It took me a while but I finally figured out!

First, a few technical details. XFree86 is reading the keyboard in raw mode which means that it wants to receive the scancode (e012) directly from the keyboard. There should not be any problem but for whatever reason, the kernel does not send the real scancode in raw mode. It first convert the scancode -> keycodes and then perform a second convertion keycode -> scancode.

The table that does the keycode to scancode convertion is in drivers/char/keyboard.c

It looks like this:

static unsigned short x86_keycodes[256] =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84,118, 86, 87, 88,115,120,119,121,112,123, 92,
284,285,309,298,312, 91,327,328,329,331,333,335,336,337,338,339,
367,288,302,304,350, 89,334,326,267,126,268,269,125,347,348,349,
360,261,262,263,268,376,100,101,321,316,373,286,289,102,351,355,
103,104,105,275,287,279,306,106,274,107,294,364,358,363,362,361,
291,108,381,281,290,272,292,305,280, 99,112,257,258,359,113,114,
264,117,271,374,379,265,266, 93, 94, 95, 85,259,375,260, 90,116,
377,109,111,277,278,282,283,295,296,297,299,300,301,293,303,307,
308,310,313,314,315,317,318,319,320,357,322,323,324,325,276,330,
332,340,365,342,343,344,345,346,356,270,341,368,369,370,371,372 };

So if I want to know which value to pass to 'setkeycodes e012' I
need to look for the value 256+0x12 = 274 (the e0 prefix means
'add 256').

The value 274 is found at index 152 so I do

setkeycodes e012 152

Et voila! The kernel does not complain anymore and I receive the proper X event when I press the key.

I had just one small problem: one of my unknown scancode
was not present in the table (e011==273) so I had to use
another scancode not produced by my keyboard.

Note: in the following the characters 'lower' and 'greater'
are discarded when I post so I replace them with ( and )

You may also want to look in /etc/X11/xkb/symbols/inet for the keyboard layouts:

> partial alphanumeric_keys
> xkb_symbols "logicdn" {
> name[Group1]= "Logitech Cordless Desktop Navigator";
>
> // Media keys
> key (I20) { [ XF86AudioMute ] };
> key (I6D) { [ XF86AudioMedia ] };
> ...

The scancode value for (I20) is found in /etc/X11/xkb/keycodes/xfree86.

> (XFER) = 129; // Henkan
> (NFER) = 131; // Muhenkan
> (AE13) = 133; // Yen
>
> (I20) = 160;

Be aware that here (I20) the prefix 'e0' has a value 128 so
160=128+32 = 128+0x20 = scancode e020
Ixx is a a simple case because it always correspond to scancode e0xx

Have fun!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.