Remapping Mouse Buttons

I have recently bought a vertical mouse for work. This is to help combat a bit of RSI in my arm. Its great, make things much better. So good that I got another one for my other office. Then I hit a snag, the two mice are slightly different versions, one is a Evoluent 4 and the other a 3. This means that mouse buttons mapped differently to functions, and neither of them mapped how I wanted them to map. So… remapping mouse buttons.

First find out which button maps to which number. Easy with a little problem called ‘xev’.

xev | grep button

The command above pops up a window which you can click in, and then filters the output to the command line.

Next look at the output from xinput

xinput -list

This will tell you the ID number of the device you want to remap.

xinput –get-button-map Device_ID

Outputs the button map, you will get something like this:

> xinput –get-button-map 9
1 3 2 4 5 6 7 8 9 10 11 12 13 14

Then you just remap the buttons that wrong by switch them over, in my case 2 and 3.

xinput –set-button-map 9 1 3 2 4 5 6 7 8 9 10 11 12 13 14

Finally to make this happen every time you log in put the following in your ‘.bashrc. file in your home directory.

MOUSE_ID=`xinput list | grep -i Evoluent | awk -F= ‘{ print $2}’ | awk ‘{print $1}’`
xinput set-button-map $MOUSE_ID 1 3 2 4 5 6 7 8 9 10 11 12 13 14

The first line finds the ID of the device, just in case it changes. The second line maps the keys using the ID.

Easy!