May 29, 2008

Add keyboard shortcuts with KeyTouch

Author: Joe Barr

KeyTouch is an application designed to allow you to make full use of all the special function keys on your keyboard, whether the hardware supports Linux or not. It's a great idea, especially with all the multimedia applications that come standard with today's PCs. But as is often the case, the devil is in the implementation details.

Marvin Raaijmakers wrote the first version of KeyTouch in 2004, after finding he could not configure the extra function keys on a new keyboard he had just bought. Today, KeyTouch is included in most modern distributions (Mandriva, openSUSE, Fedora, and Ubuntu, to name a few) and the project is actively seeking packagers for other distributions. If you want to download and compile the application yourself, you'll need to have the development versions of libxtst and libgnome-menu installed.

The current shipping version of KeyTouch comes with more than 80 predefined keyboards included. None of my keyboards for either of my desktop boxes were among them, but that's not an uncommon occurrence. The KeyTouch-Editor, which allows you to assign commands, programs, or functions to specific keys also allows you to create your own keyboard configuration file for unsupported hardware.


On my Ubuntu 8.04 desktop box, I installed KeyTouch, KeyTouch-Editor, and the recommended menu package -- no, not libgnome-menu, but a package named menu. KeyTouch and KeyTouch-Editor then appeared on my System -> Preferences menu. After selecting KeyTouch-Editor, you're asked to select your keyboard from a list of devices, which includes mice, speakers, and other devices. As you can see in the accompanying image, the list I was presented with included a PS/2 keyboard, so that's the device I chose. Next, you're asked to press one of the function keys on the keyboard, to be sure that you've chosen a valid device.

KeyTouch-Editor allows you to create a new definition file or select an existing one to work with. Once you've done that, you can start making assignments on a key by key basis. I kept it simple. I decided on using one F-key to begin playing an MP3 file, another to increase the volume, and a third to decrease the volume.

Selecting F1 as one of the keys to assign a function to brought me face to face with the first implementation issue. GNOME uses the F1 key as its help key. Further experimentation revealed that the F5 key also has a prior assignment, evidently to refresh the desktop. It appears that if an application and GNOME fight over a key, GNOME wins. I searched for a way to alter those assignments, and found a tip in the Ubuntu forums, but that tip didn't offer a reboot-proof solution, so I took the easy way out and used F2, F3, and F4.

The KeyTouch-Editor user interface is not perfect, but it's better than searching for and tweaking obscure configuration files. To add a function, click New, press the key you want to assign to the function, then enter a name for the key. The key will then show up in the list of assigned keys displayed in the UI. Highlight it by clicking on the name, and its settings will appear as well. For a new key, the only thing that's been assigned is a name and the scancode KeyTouch detected when you pressed it. You still need to add a keycode, which is just a brief description of what the key will do, and then specify the action to be taken when it's pressed, whether that be a command, program, or function.

You must select a unique keycode from the available list for each key assignment. Once that's done, you're ready to actually assign the functionality. For F2, I selected program, and then entered the command play /home/warthawg/tradesecrets.wav in the text box. For F3 and F4, I selected Special Action instead of program, then chose Amixer for the plugin, Volume increase for F3, and Volume decrease for F4.

When you save the configuration file in KeyTouch-Editor, you're offered the opportunity to send the file to the developer, so that your keyboard definition can be added to the list of those included in the package.

When you've finished your function key definitions and saved the file, you still have to do a little bit of work before you can use them. To tackle the last few chores, exit KeyTouch-Editor and start KeyTouch. Proceed to the Keyboard tab and click Change. If you're adding a new keyboard, you'll need to import it. If you're changing an already installed keyboard file, find and select it from the scroll list, which is organized by manufacturer and model.

I ran into another implementation issue at this point the first time I tried to update a keyboard file that I had added earlier. KeyTouch would not let me update the previously imported keyboard definition because it believed the existing data was newer than the file I wanted to import. The problem -- which has been reported to the developer and possibly corrected by the time you read this -- is in the way the last update date is stored and interpreted.

I examined the XML file KeyTouch used for the definition I had added, and it showed the last update date as "09-05-2008." That was absolutely correct in European style date formats, but wrong as a US style date. The software was reading the date as September 5, not May 9. After I changed the date to "05-05-2008," everything worked as it should.


I found KeyTouch's interface to be less than fully intuitive. I recommend that you download and peruse the PDF docs available for both KeyTouch and KeyTouch-Editor if you're interested in using this tool. The bug I found in the Ubuntu implementation also made it less than stellar in terms of ease of use. On the other hand, if you're the adventuresome type and you want to do some cool things with your keyboard special function keys, KeyTouch might be the tool for you to realize that goal.


  • Tools & Utilities
  • Desktop Software
Click Here!