All these buttons are detected by the latest kernel (which as of writing is)
$ uname -a
Linux taichi 3.7.4-204.fc18.x86_64
This is great news because all we need to do now is map each button against the desired application/keystroke.
My system of choice is Ubuntu 10.10 as of writing, this has since changed to Fedora so all the command line and install command listed are correct for this distributions as of writing. If you find other commands work on other distributions leave a not in the command and I will be sure to update the main article.
The Install Instructions for a fresh install
We should install xbindkeys. This will re-map mouse and keyboard inputs so the install is…
$ sudo apt-get install xbindkeys
The goal is to configure the mouse buttons to send key combinations to activate o
ther desktop or application functionalities. Technically all xbindkeys is doing is executing an application in response to a keystroke or mouse button.
So in-order to map a mouse button to a keystroke we have to install an application called xte, which in Ubuntu comes as part of the xautomation package which can be installed like this
$ sudo apt-get install xautomation
Now we need to create a configuration file for xbindkey, which can be done like this…
$ xbindkeys --defaults > /.xbindkeysrc
We need to edit this file in a text editor. I use nano, but vim, kate or gedit are just as good but you can of course use what ever editor you would prefer to…
$ nano -w ~/.xbindkeysrc
The xbindkeys configuration file has a very simple format…
"command_to_run"
keyboard_or_mouse buttons
So we need to add our button-to-key configurations, but first we need to know what ‘events’ the mouse buttons are triggering before we can remap them. For this we can use xev, this program is a key and mouse event sniffer. It runs by opening a small window. You can now start pressing keyboard or mouse buttons over the window and see if they are detected. For example the forward button on my Logitech Revolution MX looks something like this:
ButtonRelease event, serial 31, synthetic NO, window 0x3200001,
root 0x263, subw 0x3200002, time 6377530, (36,35), root:(38,122),
state 0x10, button 13, same_screen YES
Bellow I’ve included a table for the Logitech MX mouse, these will probably be if you have a newer, or older mouse
Now that we have a list of all our button codes we can move on to actually writing the configuration file. For example I have this to map the Thumb Button Up and Thumb Button Down buttons to switching workspace in my Gnome shell, these keycombinations are specific to my setup so you will need to chnage them. What I’m doing here is pressing the ‘Windows’ key ‘Left Control’ then ether ‘Down’ or ‘Up’ then releasing the other two keys…
"'xte' 'keydown Super_L' 'keydown Control_L' 'key Down' 'keyup Super_L' 'keyup Control_L'"
b:8
"'xte' 'keydown Super_L' 'keydown Control_L' 'key Up' 'keyup Super_L' 'keyup Control_L'"
b:9
The Rapup Now we make it all work
Thats all there is. Once you have setup your /.xbindkeysrc confirguration file, you just need to configure xbindkeys to run automatically on system startup. This is going to be different depending on your windows manager, but here are the steps for KDE and Gnome
Gnome3
There’s a tool in GNOME 3 which allows you to add, modify and remove autostart entries and you can run it by executing from a terminal or from the ALT+F2 dialog. Just run gnome-session-properties
Click on “Add”
Write ‘Xbindkeys’ in the Name and ‘/usr/bin/xbindkeys’ as the Command and press OK.
And done
Open System Settings.
Go to Advanced tab -> Autostart.
Click on “Add Program…”.
Write ‘/usr/bin/xbindkeys’ and press OK. A new dialog pops up. Press OK again.
Done!
I hope this helped you!