Mapping IntelliMouse buttons in xorg.conf

Q I have an IntelliMouse, with seven buttons: 1 = left, 2 = middle, 3 = right, 4 and 5 = wheel, then 6 and 7 as extra buttons by my thumb. I want to use those last two buttons for something like volume control or maybe track-skipping in Amarok. As far as I can tell, this can't be set up in the xorg.conf file. Can you help?

A First you need to make sure that all seven buttons send events to X. Run xev from a terminal and click the various buttons while the window is active. If the button is recognised, you'll see something like this:

ButtonRelease event, serial 31,
synthetic NO, window
0x3600001,
root 0x5a, subw 0x0,
time
191458267, (86,1 1),1
root:(91,162),
state 0x1 button 4,
10,
same_screen YES

If you get no events from the extra buttons, edit the mouse section of xorg.conf. You should already have a ZAxisMapping line, so change this to the two highest numbered buttons and add a Buttons line to indicate the number of buttons. This is how it looksfor my seven-button mouse:

Section "InputDevice"
Identifier "USBMouse"
Driver      "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "Buttons" "7"
Option "ZAxisMapping" "6 7"
EndSection

Restart X and run xev again to make sure the buttons work. Your extra buttons will be 4 and 5 - the wheel is now 6 and 7. Now you need to map these events to actions. A useful program for this is XBindkeys, available from http://hocwp.free.fr/xbindkeys or possibly in your distro's package repository. XBindKeys uses a simple config file to map keyboard and mouse events to commands. For example, you might want to do

"firefox"
b:4

in ~/.xbindkeysrc. This will cause it to start Firefox when you press button 4. To control Amarok, or any other KDE application, you'll need to investigate DCOP (Desktop Communications Protocol). Run kdcop and look at the commands that Amarok accepts. Execute the commands from kdcop and it shows the command line DCOP call that will do the same thing from a script, or XBindKeys. You will need to experiment to find what you need, but for starters, this will skip to the next track in Amarok:

dcop amarok player next

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar