On this page

How To Utilize Your New Multimedia Keyboard Under Linux

Overview:

Xbindkeys is a program that allows you to launch shell commands with your keyboard or your mouse under X Window. It links commands to keys or mouse buttons, using its configuration file. It does not depend on the window manager and can capture all keyboard keys.

After that go to the directory where you downloaded the source and unpack it with tar:

cd your_download_dir

Uncompress the source (1.x.x - refers for your version):

tar xzvf xbindkeys-1.x.x.tar.gz

Change to the new directory (created by tar):

cd xbindkeys-1.x.x

Install the program (as root):

su rootmake install

Configuration

The program is configured by the use of a file, .xbindkeysrcin your home directory. It is recommended to use the default configuration and then you can edit it according to your needs.

xbindkeys --defaults > $HOME/.xbindkeysrc

If you open the file with a text-editor you can see its structure:

# Next Track - Alt + Up

"xmms --fwd"

m:0x8 + c:98

# Previous Track - Alt + Down

"xmms --rew"

m:0x8 + c:104

It is pretty obvious, it has the command to be executed enclosed in quote characters, then a line after the keyboard codes which will cause that command to be executed. The line starts with hashmark (#) is for comment, recommended strongly. To find out the keycode you can do with:

xbindkeys -mk

This will pop up a window and show the keycodes when you hit keys. To quit when you done with your buttons press "q".You can check your current keys and commands with:

xbindkeys --show

Once you have setup your .xbindkeysrc you can start the program by running:

xbindkeys &

This runs the command in the background causing to listen for keyboard events and execute the commands it knows about when finds a combination listed in its config file. To start xbindkeys when you login:the best way to do this, as long as you're logging in via KDM or GDM, is to put xbindkeys in your ~/.bashrc file.

NOTE:

You can use xbindkeys-config, a GUI utility for editing your .xbindkeysrc. It can be installed with apt-get. Please note, create the config file with

xbindkeys --defaults > $HOME/.xbindkeysrc

before using the graphical application otherwise it will crash on saving.

Now, you are done. You can start using your extra buttons without installing any special driver!

5 Comment(s)

Comments

I'm afraid that in looking into the more complicated solution, you've overlooked some great resources that are already available to use with much less setup. The best program for multimedia keyboards in linux is called "keyTouch" and is available at http://keytouch.sourceforge.net/.

Both of these programs require the user to simply select the keyboard and their multimedia buttons work with no more configuration. keyTouch allows the user to add or change the commands, all without delving into the command line.

Yes, your program may be more suitable for more complex stuff but it depends on the kernel. Xbindkeys does not depend on anything, that's why I chose it for setting up my keyboard with it. Actually it has a GUI frontend for setup as I mentioned in the tuto but I found it more uncomfortable using it than editing a little text file.Anyway, thanks for your comment.

It is unfortunate that that the author did not cover the technologies involved, and discuss all the possible solutions.

Both KDE and GNOME (not sure about other desktops) have comprehensive native support for multimedia keys. For both desktops, the only thing that you need to do is ensure that your keyboard layout is configured correclty. This is best done by setting the "XkbModel" option in Xorg.conf (as the X server is really the only thing that can know what keyboard model you have - especially if you use applications/X remotely, or have the same home directory on multiple machines).

However, this does require that X knows what the keycodes should translate to - but in the end it is much more useful for people to contribute their keyboard definitions for X than waste time with workaround utilities (such as xbindkeys, lineak etc etc).

Quick howto for anyone using KDE with a keyboard X has a valid layout for:

1)Find correct keyboard layout (if you don't know it already). Start KDE Control Center, find the "Keyboard Layout" tool (under Regional & Accessibility on my Mandriva install running in English). Click the "Layout" tab, ensure that the "Enable keyboard layouts" option is checked, then select the a candidate from the "Keyboard model" drop-down box, and click Apply. Select the "Keyboard shortcuts" tool, and start creating a new shortcut, just so you can test the keys (and what Symbols they are sending). If the layout doesn't work with all your keys, repeat ...

2)Once you have found the right keyboard layout, return to the "Keyboard Layout" tool, click on the keyboard listed under "Active layouts" to see the command that was used (in the "Command" field). Take the value after the -model flag, and then add a XkbModel option to xorg.conf. In my case, my InputDevice section for my keyboard looks like this:

If you use the same home directory on multiple machines, uncheck the "Enable keyboard layouts" option in KDE Control Center (so that you don't set the wrong keyboard layout after X has started).

Note that on Mandriva, the keyboard configuration tool (drakkeyboard) can also be used to set this up, and if your hardware has a specific keyboard type the OS installer knows about (e.g. Dell Inspiron laptops), this should have been setup by default.

3)Now, return to "Keyboard shortcuts", and you can set up any global or command shortcuts. Also, you can use your multimedia keys from any KDE application with keyboard shortcut support (e.g. amarok, kaffeine, kmplayer etc.)

If you don't find a suitable model in step (1), this means that X does not have the information for your keyboard, the best thing to do is to update the keyboard map, and provide a patch to X.org for your keyboard. This can't be covered here, but see (for example) /usr/share/X11/xkb/symbols/inet (or similar, may differ on other distributions). Updating this is not difficult (just takes some patience).

You are pretty much right, it is important to setup your hardware correctly and get it recognized by X. But as I metioned in the tuto xbindkeys does not depend on the windowmanager. So your comment is great for those who use KDE. But what about Gnome or Xfce?

Just what I wanted. A non-session-manager method to customize my buttons. I don't want the KDE, Gnome, or even XFCE control panel manager thing. I setup my own X session without them.

In responce to the other commenters saying "there is a better way - be a sheep and only want what the leaders tell you you want", I say "Fooey!" I like Linux because I _can_ (mostly) make things work _for_ my _my_ way - not have to adapt my use to whatever "the system" says is best.
So I want the buttons for my own uses - not necessarily the same as what is silkscreened on the keyboard. For example, I use the button labeled "mail" to open an xterm.
hotkeys is just right for me. Customizable and easy. And this tutorial explained it well enough it was very easy for me to get setup. I did use hotkeys man page for further details. *smiles*