For most people, the default key bindings in their system might be more than adequate. But for others, whether it happens to be because your mulitmedia keys don’t work with a certain player, or there is a command that you run over and over again and want to program it into a key you don’t use for anything else, for those people it turns out to be a simple process to setup these key bindings.

On my current system, Gentoo, there were three things that convinced me to customize my key bindings. The first and most pressing of the three reasons was the fact that my volume control keys changed the volume on the wrong sound card, it it turned out to be simpler to use manual commands to change the volume than it did to reconfigure the entire system to recognize the sound card I use as the main one (see Dealing alsa defaults and a second sound card on Gentoo for more information on this). The second reason was I use Amarok (although I’m still looking for a better player) rather than a Gnome music player, and so the multimedia keys do not control it unless you install a script that allows it to do so - less reliable then my method all in all. The final reason was to make a command easier to input, specifically the command I use to hibernate my monitors - xset dpms force off.

These commands have been tested on Ubuntus 9.04 through 10.04 and Gnome version 2.28.2 on Gentoo.

The only application that does not come with Gnome by default that you will require is gconf-editor.

Begin by opening up both the Keyboard Shortcuts program (found in System >> Preferences >> Keyboard Shortcuts) and gconf-editor (use Alt-F2 and type it in the Run Application dialog).

In gconf-editor, go to apps >> metacity. The two important folders within metacity are keybinding_commands, which allows you to set the commands that you with to have run and global_keybindings, which allows you to set the key code of the key you wish to set to run the command

Each Run_commandin global_keybindings corresponds with the same numbered command in keybinding_commands, so filling these out is relatively simple.

Enter your desired command into command_1 by double clicking on it and filling out the Value field.

Now switch to the global_keybindings, double click on run_command_1 and enter the key code value into its Value field. If you do not know this code, a simple way to discover it is to maximize the Keyboard shortcuts and click in the shortcut field of one of the Actions, then hit the button you desire a code for. Copy the code that appears there into the Value field of run_command_1, then switch back to the Keyboard Shortcut window and hit backspace to clear the Shortcut (it should read disable) so that the two settings do not conflict.

Repeat this with as many of the other commands and keybindings as you desire.

In some cases, a complex command may have to be put into a script before it will run, such as in the case of sleep 10 && xset dpms force off (sleep being required for the command to function consistently). To do this, create a script like the one attached, make it executable (for example, the attach script could be make executable by running chmod +x and then enter the path to the script into the value for the command rather than the command itself (for example, the value would be /home/user/bin/ in my case).

Some buttons already have an entry in keybinding_commands and so none in global_keybindings, being preset by gconf-editor, for example the command_screenshot binding, which controls what command is executed when you press PrtScn (or any variation thereof). In my case, I changed it to gnome-screenshot --interactive so that it would present me with options as to what kind of screenshot I wanted to take rather than just take one of the whole desktop.


sleep 10s

xset dpms force off

exit #