Configuring a Logitech Cordless Desktop Pro Keyboard

This page describes how to setup a Logitech Cordless Desktop Pro keyboard to allow the usage of the hotkeys, such as homepage, e-mail, search, and the multimedia keys for controlling the playback of MP3 with XMMS, and adjustment of the volume.

Although mainly written for this specific keyboard, the items described here should provide important pointers for everyone who wants to configure any kind of internet keyboard.

For XFree-4.3 and MetaCity, don't forget to take a look at the update.

I have also stumpled upon the xmms-itouch-plugin, but on my system, it keeps crashing XMMS. If you can make it work, it is an xmms-plugin to take care of all the keybindings. The major advantage is that you do not need to configure the special keys i X, since the plugin just uses the keycodes. Still the right way to do it is to bind the appropriate names by configuring your X-keyboard.

A disadvantage of using the xmms-itouch plugin is that the keybindings will only work if xmms is running. For the multimedia-keys, this is indeed the best way to handle it, since the plugin knows about the state of xmms. Since I have not been able to make it work, I do not know how it handles play/pause etc, but it should be easier to make this in a plugin. On the downside, I like my setup, where I can start xmms by pressing the play-button. Also the volume-controls work without xmms running (as well as the other hotkeys).

There are also several different daemons that can assist in the handling of the extended multimedia keys. At one point I was using Acme, which is in fact an applet for Gnome, for handling these keys. I was only using this for the volume up/down and mute buttons, but at some point these functions were merged into the Gnome Keyboard Shortcuts properties, so this is what I use now. There is also another daemon called Hotkeys which does about the same thing, but uses XOSD to give a nice TV-style OSD volume bar when turning up/down the volume.

The XFree-86 Keyboard Driver

The first step is to configure the X-server to correctly interpret the scan-codes of the keyboard events. To do this, edit the /etc/X11/XF86Config-4-file to include the following section:

Section "InputDevice"
        Identifier  "Logitech Cordless Desktop Pro"
        Driver      "keyboard"
        Option      "CoreKeyboard"
        Option      "XkbRules"  "xfree86"
        Option      "XkbModel"  "logicordless"
        Option      "XkbLayout" "dk"
EndSection

This defines an input-device for the keyboard. The important thing is to have logicordless or itouch as the XkbModel. If you do not have exactly this kind of keyboard, take a look at /etc/X11/xkb/symbols, and see if you can find one that suits your needs better. As I will show you in a moment, there is still a possibility to modify the settings, if you cannot find one that matches your keyboard exactly.

By the way, you should set XkbLayout for the appropriate keyboard layout. Since I have a danish keyboard, I use dk.

Now, to use the input device, modify the section called ServerLayout, to include the following line:

InputDevice "Logitech Cordless Desktop Pro" "CoreKeyboard"

Of course you should use the identification you gave the keyboard in the InputDevice-section. Now, restart the X-server (Ctrl-Alt-Backspace) to load the new configuration. Log in and use xev to verify that the keyborad mappings work.

xev opens a window which is able to receive keyboard and mouse events. For each time you press a key, you will get some lines in the console where you started xev, showing various information about the event. For instance, pressing the "homepage"-button yields the following event information:

KeyPress event, serial 28, synthetic NO, window 0x2000001,
    root 0x3d, subw 0x2000002, time 3437319439, (27,35), root:(41,62),
    state 0x0, keycode 178 (keysym 0x1008ff18, XF86HomePage), same_screen YES,
    XLookupString gives 0 characters:  ""

KeyRelease event, serial 28, synthetic NO, window 0x2000001,
    root 0x3d, subw 0x2000002, time 3437319568, (27,35), root:(41,62),
    state 0x0, keycode 178 (keysym 0x1008ff18, XF86HomePage), same_screen YES,
    XLookupString gives 0 characters:  ""

The important information here is the keycode (178) and the keysym (XF86HomePage). If the driver is not loaded correctly, you will see "keysym 0x0, NoSymbol" when the shortcut-keys are pressed.

Modifying keyboard layout with modmap

For some reason, the Logitech-driver does not include a mapping for the Logitech-key (top right, just above the numerical keypad). To map this key, insert the following line in /etc/X11/Xmodmap:
keycode 161 = XF86VendorHome

If you do not want to use this configuration system-wide, you can put it in ~/.xmodmap instead.

You can also use this approach if you want to bind some other keys, perhaps because your keyboard does not have an entry in /etc/X11/xkb/symbols.

You must use an existing name for the key. Find one that suits your needs from /usr/X11R6/lib/X11/XKeysymDB. As you can see, I have chosen XF86VendorHome for the Logitech key.

Restart the X-server for changes to take effect. (You may also load the new settings, but this is left an exercise for the reader. Try man xmodmap for a pointer).

You should now see that all keys generate appropriate keysyms. If not, double check your xmodmap configuration.

Binding the keys

The only thing left to do, is the binding of the keys to appropriate functions. Since I use Sawfish under Gnome, I will explain how to configure this. If anyone has information on how to setup other window managers, feel free to write me, and I will try to include the information on this page.

To setup Sawfish keyboard bindings, start the Gnome Control Center, either from the menu (Programs → Utilities → GNOME Control Center), or type gnomecc in a terminal. Now go to "Sawfish Window Manager" and "Shortcuts".

Since I prefer the shortcut keys to have the same effect regardless of which window is focused, I setup the shortcuts under the context "Global". For key bindings that apply to the active window, or similair functions, simply select the appropriate context.

Now add the new keybindings for the keys. I use the following:

XF86AudioRaiseVolumeRun shell command: aumix-minimal -w +5
XF86AudioLowerVolumeRun shell command: aumix-minimal -w -5
XF86AudioMuteRun shell command: aumix-minimal -w 0
XF86SearchRun shell command: galeon http://www.google.com/
XF86HomepageRun shell command: galeon http://www.symlink.dk/
XF86AudioPrevRun shell command: xmms -r
XF86AudioNextRun shell command: xmms -f
XF86AudioStopRun shell command: xmms -s
XF86AudioPlayRun shell command: xmms -p
XF86StartXterm
XF86MailRun shell command: gnome-terminal --solid -t "Mutt e-mail client" -e mutt
XF86VendorHomeRun shell command: gcalc

As you can see, there is room for improvement:

There is one caveat, which needs to be addressed: programs running in a terminal. Under normal circumstances, these do not get a terminal, and most of them will as a result terminate immidiatly. This is the case with mutt, my text-mode email program. I have solved this by explicitly running gnome-terminal, letting it start mutt. The --solid-option is used to make mutt open in a non-transparent window, and is only needed because I have the default behaviour of gnome-terminal set to provide a "transparent" terminal (e.g. the backdrop/wallpaper is shown in the background of the terminal window). Perhaps the Sawfish shortcut configuration could be extended to provide a "Run in terminal"-option, as the one available when adding icons to the Gnome-panel. Of course this would still give the default terminal, not my additional --solid.

Update

I have installed RedHat 9.0, which comes with XFree86-4.3 and Gnome-2.2, and per default uses the MetaCity window manager. A couple of things have changed from what I described above. I will try to clarify here. First of all, the name of the keyboard-model changed. There is no longer anything called itouch or logicordless. The name of the model is now logicdp. Of course, if you do not have exactly this keyboard, you should find the one that is appropriate for you in /usr/X11R6/lib/X11/xkb/symbols/inet. Unfortunately this is not easily discovered, since all keyboards use the CoreKeyboard-driver, so X still starts if the model is not set correcly, but of course it does not work. Make sure that xev shows the correct events before trying to bind the keys.

On the positive side, using the logicdp-keyboard model, the Logitech-button (in the upper right corner of the numerical keypad) is now mapped to XF86VendorHome, so you will not need to do this by xmodmap.

Once the driver is configured and events can be seen with xev, we are ready to bind the keys. Since I'm using Gnome, and the default window manager is MetaCity in RedHat's distribuition, I had to find out how to bind keys in this setup.

MetaCity uses the "registry database of Gnome" known as gconf. As of this writing only some of the keybindings can be configured from the "Keyboard Shortcuts"-configuration. For other keys, you will have to use the Gconf editor. The Gconf editor can be started from a terminal (the name of the program is gconf-editor or the menu (on my RedHat 9.0 system it is in Main Menu > System Tools > More System Tools > Configuration Editor.

Now browse down to apps > metacity > global_keybindings. You will see that there are a range of keys called run_command_1 to run_command_10. This is where you put the key binding you want to activate whatever program or script you want.

In apps > metacity > keybinding_commands there are keys named command_1 to command_10, which hold the name of the command to execute. Remember that you may need to call the terminal explicitly if you want to call a text-mode application.

I have successfully added more keybindings than the default 9 (the first is used for Ctrl-Alt-Del on my RedHat system). Simply add the two keys run_command_n and command_n to the correct folders. I had some problems when creating the run_command_n-key first, so first create command_n, then bind the key. Keybindings should be entered as shown by xev. You can use this reference to get some ideas for the keys:

command numberKeybindingcommandDescription
run_command_1<Ctrl><Alt>Deletegnome-session-save --killDisplay Logout dialog
run_command_2XF86Standbygnome-session-save --killDisplay Logout dialog
run_command_3XF86AudioPlayxmms -pStart xmms playback
run_command_4XF86AudioStopxmms -sStop xmms playback
run_command_5XF86AudioPrevxmms -rPrevious track
run_command_6XF86AudioNextxmms -fNext track
run_command_7XF86VendorHomegnome-calculatorStart calculator
run_command_8XF86AudioRaiseVolumeaumix-minimal -w +5Raise volume
run_command_9XF86AudioLowerVolumeaumix-minimal -w -5Lower volume
run_command_10XF86AudioMuteaumix-minimal -w 0Mute
run_command_11XF86Searchgaleon http://google.comSearch
run_command_12XF86Mailgnome-terminal --window-with-profile=Mutt -x muttStart mutt e-mail client
run_command_13XF86WWWgaleon http://symlink.dkOpen my homepage

As you can see, the first keybinding is Ctrl-Alt-Delete, which calls gnome-session-save --kill. This causes the Logout dialog to show up, allowing the user to logout, shutdown or reboot the machine. This was actually one of the things I was missing in my old configuration, but I guess this is the way to do it, and I assume this would work with an older Gnome with Sawfish as well.

There is still room for a few improvements (althoug this is exactly the same as with the old configuration). First of all, I would like the play/pause button to actually toggle. Since xmms does not have a toggle-option, the only easy way of doing this is by using shift-play on the keyboard (which actually generates an XF86AudioPause-event) to call xmms -u. To make the toggle work, there are two options: Either modify the xmms source (and try to make the xmms developers accept your changes into the official release), or write a small program to control xmms. The latter approach may not be too hard if taking a look at Xmms-shell. On the other hand, the extra switch to xmms would have the nice side-effect of starting xmms if it is not already running. I have not yet decided which solution to go for, but I will post it on this site as soon as I solve the problem. Update may 2005: This is now possible with the -t-switch to xmms.

The problem of the mute-button toggling the sound on and off instead of simply setting the level to 0 should not be too hard to fix. Actually I thought of using xosd to show a nice volume-bar, as well as muting information. This will probably be a small mixer in itself, constituting this. Xosd actually contains an xmms-plugin that does this, but of course this only works when xmms is running, and does not support the muting function.

Regarding the ability to spawn only one instance of a given executable, I will probably look into a way of doing this as well, since you only need one calculator (or mail program), but bringing up the one that is already running would be a really nice feature when using the hotkeys.

Update Part deux

(2005.05.28)

Quite some time has passed since this page was written, but judging from the feedback I have gotten from various people, this is one of the more popular pages on my site, so I decided to put some updated information here. I am still using Gnom (at this point version 2.8.2 under Gentoo), and using the Metacity window-manager. This means that most of the descriptions for how to set up the multimedia-keys are the same as described above. Even though I have switched to X.org this has not changed much of the configuration. I use the logicdp-driver under X.org X11 v. 6.8.2-r1.

The problem with XMMS play, pause and unpause has been solved, since XMMS now has a -t-switch which handles this. Using this, I can still launch XMMS by hitting the play-button, but I can also pause the music if XMMS is already running.

The mute/unmute issue has been solved by using the builting keyboard bindings in Gnome.

Here are my current keybindings:

command numberKeybindingcommandDescription
run_command_1XF86AudioPlay/usr/bin/xmms -tStart/pause xmms playback
run_command_2XF86AudioStop/usr/bin/xmms -sStop xmms playback
run_command_3XF86AudioPrev/usr/bin/xmms -rPrevious track
run_command_4XF86AudioNext/usr/bin/xmms -fNext track
run_command_5XF86HomePage/usr/bin/firefox http://symlink.dkOpen my homepage
run_command_6XF86Search/usr/bin/firefox http://google.comSearch
run_command_7XF86Go/usr/bin/gnome-terminalStart a terminal
Last updated: 2005.05.28