Why Johnny Can't Hit Volume Up

Introduction

Go to visit a mass market store like Target or Wal-Mart these days to buy a keyboard and you may be surprised. Once upon a time you might be able to pick between a couple of barebones units which had the most basic keys plus the ubiquitous "Windows Key" (aka "Start") and "Menu Key". But times have changed and computers are so common that the grocery store sells blank CDs and my local Target has at least a dozen different keyboards to choose from. They come in a wide price range and have a variety of features but even the cheapest of them, the most commodity of keyboards, is festooned with extra keys to open your mail application, a web browser, turn the audio volume up/down, etc. All are quick shortcuts to browsing over and over again for a frequently visited directory, finding a program buried in a menu somewhere, or mousing over to a miniscule icon to perform an action (like muting sound playback so you can answer the phone). My own keyboard is a Microsoft Natural Multimedia Keyboard and at the top of the keyboard it features the following keys: My Documents, My Pictures, My Music, Mute, (Play)/(Pause), (Stop), +, -, (Prev), (Next), Mail, Web/Home, Messenger, Calculator, Log Off, and Sleep

It also doubles up the use of the function keys by having a "F Lock" key. When on, the F Lock makes the function keys do what the function keys on any other keyboard would do. When off, the function keys issue a completely different set of keycodes and presumably if I was on Windows (and I had the right driver installed) they would perform the functions indicated by the second set of labels they all have. They are labeled: Help, Undo, Redo, New, Open, Close, Reply, Fwd, Send, Spell, Save, and Print

False Starts

Now, if you're like me you've got all those wonderful keys and you just want an easy way to assign something to each one so you can use them. Also, if you are like me you might have tried looking on the Fedora menu for something to set up your keyboard and you found both the Keyboard and Keyboard Shortcuts programs on the Preferences menu. Unfortunately, neither one of those is going to do what you want.

Setting basic keyboard behavior using the Keyboard Preferences.

Keyboard Preferences is the place you need to go if you need to alter basic properties of the keyboard (e.g. repeat rates) or turn on and off accessibility options for users who have physical difficulties manipulating a keyboard (e.g. someone who uses a mouth stylus to type and who cannot hold two keys down simultaneously).

You can connect some actions to keyboard keys under Fedora, just not nearly enough.

Keyboard Shortcuts does allow you to assign specific actions to keys but it does so in the most peculiar way.  It has a list of a handful of desktop actions and another small set of window managment actions and you can assign different keys to each of those actions. This is pretty much the exact reverse of how most people are likely to want to set up a keyboard. After all, you don't want the list of what you can do with your keyboard dictated to you, you want to dictate to Fedora what you want to do. On top of that it appears that it is not comfortable connecting just "any" keyboard key with one of the actions. When I selected "Toggle maximization state" it asked for me to type the new key. With the F Lock key off I pressed the Print key. I thought it might be nice to have a key I could assign to minimization. Keyboard Shortcuts immediately set the action to "Disabled" so obviously it saw that I pressed a key but it didn't end up getting assigned to the action. That's not good.

Even Acme, another program for making extra keyboard keys work follows this same broken paradigm. You are given a list of actions that someone else has decided you can tie to keyboard keys and the program will help you assign a key to each one.

What Should Be

A far more sensible thing would be to look at what everybody is trying to accomplish with programs like Keyboard Shortcuts and Acme and what the user is trying to do that these programs won't let him/her do. Each program has a list of actions which they know the user may want to do like minimize a window or reduce the sound volume. In that respect they are both like the Sound program under Preferences. Certain events will happen and you need to be able to attach a key to each if you want to. But keyboard events differ from sound events because sound events come from within programs so it is possible to know all the available events ahead of time. Keyboard events are driven by you hitting keys.

The only way to replicate the sound model for the keyboard would be to list every possible key event (including ones modified by other keys like Alt+A, Ctrl+A, or even Ctrl+Alt+A) and then allow the assignment of actions to the keys. But that's going to be one heck of a long list of key events. I doubt we will see a keyboard program that works that way so what a better keyboard setup program under Fedora would offer would be a list of actions which we know the user may want to assign to keys plus the ability to add all new named actions to the list. Then I can create a new action called "Run Web Browser" and it has the command to run Mozilla or a link to it. Then with the action in the list I can assign my Web/Home button to that action.

Note that this is basically the model that Fedora currently uses for the File Types and Programs program (also under the Fedora Preferences menu). The system comes with certain types of file extensions known to it (like .JPG or .OGG) and it has some programs assigned to handle those file extensions. But you can come along and both remap what programs are used to handle the extensions and even select a new program or type in a command to be executed instead. So maybe someone will cannibalize the File Types and Programs setup to generate a new preferences application for the keyboard.

What Is

Until this happens though, I'm going to suggest using the program Hotkeys. It actually follows the model I mentioned above (which I said is ultimately impractical) where it has a list of all the keys to which you can assign an action and then you can use a separate file to specify the action to tie to each key. The way it makes it sort of practical is that the keylist for a given keyboard only includes the extra keys for the keyboard. For example, here is a Hotkeys keyboard specification file for my Microsoft Natural Multimedia Keyboard:
<?xml version="1.0"?>
<definition>
<config model="Microsoft Natural Multimedia Keyboard">
<PrevTrack   keycode="144"/>
<Stop        keycode="164"/>
<Play        keycode="162"/>
<NextTrack   keycode="153"/>
<VolUp       keycode="176" adj="2"/>
<VolDown     keycode="174" adj="2"/>
<Mute        keycode="160"/>
<WebBrowser  keycode="178"/>
<MyDocuments keycode="101"/>
<Email       keycode="236"/>
<Calculator  keycode="161"/>
<Sleep       keycode="223"/>
    <!-- Media key -->
<userdef keycode="237" command="/usr/bin/xmms">XMMS</userdef>
    <!-- My Pictures key -->
<userdef keycode="228" command="nautilus /home/john/MyDocuments/MyProjects">My Projects</userdef>
    <!-- My Music key -->
<userdef keycode="188" command="nautilus /home/john/MyDocuments/MyMusic">My Music</userdef>
    <userdef keycode="133" command="">Messenger</userdef>
<userdef keycode="150" command="">Log Off</userdef>
<userdef keycode="223" command="">Sleep</userdef>
</config>

<contributor>
<name>John Munsch</name>
<email>JohnMunsch@zwave.com</email>
</contributor>
</definition>
Some of the keys have names which are already defined by Hotkeys (e.g. NextTrack) while others I've defined using a "userdef" below to create a new key, specify the text which appears on the screen briefly when I press the key, and the command to execute. When this file (named msnatmult.def) is combined with the hotkeys.conf file and both are put into a .hotkeys subdirectory underneath my home directory I can run Hotkeys and it will know what special keys to watch for and what to do when they are pressed. Here is the hotkeys.conf file I use with the keyboard definition above:
############################################################
# 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=msnatmult
CDROM=none
WebBrowser=mozilla
Email=evolution
Calculator=gnome-calculator
MyDocuments=nautilus MyDocuments
Messenger=
I know this is far from a perfect solution as far as a lot of readers are concerned. Editing files, figuring out where to put them and how to install and run programs is not something many of you will want to do. Then again, Windows has its own set of problems when it comes to handling keyboards with extra keys because it depends on your installing special drivers to handle them. If a new version of Windows ever ships which cannot load older keyboard drivers a host of keyboards from dozens of vendors will suddenly become normal 101 key keyboards and all the extra keys will be useless.
 
Creative Commons License
This work is licensed under a Creative Commons License.