06 September 2010

Remap mouse buttons in Ubuntu 10.04, to have middle button as 'back' in browser

Ok, so i tried a bunch of programs, like btnx and imwheel, but nothing worked. Btnx worked, but had some weird side effects, such as holding down the alt key every time i pressed the mouse button, so i had to physically press the alt button on the keyboard to stop the 'alt signal'.

The solution was simple:

First, get the name for your mouse


$ xinput list

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PS/2 Generic Mouse id=11 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)]
⎜ ↳ Macintosh mouse button emulation id=13 [slave pointer (2)]
⎜ ↳ Logitech Trackball id=16 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ HP Webcam [2 MP Macro] id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]



Find the mouse. My mouse has the name "Logitech Trackball".

A fancier mouse with more buttons will have a button for 'back' in the browser, so i wanted to set my middle mouse button to that signal.

First, just for fun, look at your current mouse map

$ xinput get-button-map "Logitech Trackball"
1 2 3 4 5 6 7


This is the standard map. The order of the numbers are 1 = left mb, 2 = middle mb, 3 = right mb, 4 = mwheel up, 5 = mwheel down

So what is 6 and 7? I have no idea :) But i know for a fact that 8 = Back on my mouse :)

I just tried mapping different numbers to my middle mouse button until it worked.

Like this:

$ xinput set-button-map "Logitech Trackball" 1 7 3 4 5 6 7

Tried it, and it did not work. So i increased it once more:

$ xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7

And it worked! I did not even had to restart X or anything, it updated instantly.

To make the change permanent, you have to add this to some startup script. I added it to the startup applications thingy in Preferences >> Startup Applications. Simply write xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7 in the command field.