Thursday, January 31, 2008

Multimedia/Internet Keyboards in GNU/Linux

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

Anthony Wong’s Hotkeys program 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 easier to configure and its osd (on-screen display) is very simillar to those available on other OS’s.

You can visit Hotkeys site to download the latest version of the program as tarball or as a debian package.

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

$ apt-get install hotkeys

Configuration

Hotkeys starts a daemon process,usually started with xinit process,it uses a global configuration file /etc/hotkeys.conf and user configuration’s can be stored in $HOME/.hotkeysrc.

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

1) Device Settings

Keyboard Type (kbd=”“) CD Drive (CDROM=”“)

The supported keyboards can be checked with ‘hotkeys -l’.

2) Key Behaviour

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 tags.

3) On-Screen Display Properties

Font (osd_font=”“) Color (osd_color=”“) Position (osd_position=”“)

#Sample /etc/hotkeys.conf file. #########################

  1. Global configuration for hotkeys # #########################

    1. These are the default values.
    2. A line starting with # is a comment.
    3. Specify the default keyboard (without the .def extension) so you
    4. 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-*-*
    5. For the color, you can either use the strings in /etc/X11/rgb.txt,
    6. or use the RGB syntax #RRGGBB, e.g. ##A086FF
      osd_color=LawnGreen
      osd_timeout=3
    7. osd_position is either ‘top’ or ‘bottom’
      osd_position=bottom
      osd_offset=25

Configure Unsupported 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 the all special keys on your keyboard.

Use the xev program to capture the keycodes and save it to file.Move your cursor to square on the xev window and press the special keys in a sequence.

$ 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 andvarious CD/DVD player controls
(See /usr/share/doc/hotkeys/sample.xml). Each ‘tag’ has a behaviour assigned, Sleep uses APM to turn your computer into hibrnatio.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.

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

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

<?xml version="1.0"?>
 <definition>
 <config model="My custom keyboard">
 <!-- Support Tags functions -->  
 <!-- half-moon key -->

 <Sleep  keycode="223"/> 
 <!-- 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 really well.If you have configured a new Multimedia/Internet keyboard using hotkeys, do take time to send it project developers, it would help many other users with same keyboards.

Web Resources

Hotkeys Help Forum

Hotkeys Project

No comments:

Post a Comment

You can leave a comment here using your Google account, OpenID or as an anonymous user.

Popular Posts