logitech-mouseThose of you using a mouse with multiple buttons, such as the one shown here, probably already know how painful it can be to make it work just as you’d like on Linux. I have myself been postponing the configuration of my Evoluent VerticalMouse for years. I recently gave myself a little kick in the butt, and came up with the following solution.

Identify your mouse

First, find the exact name of your, and copy it somewhere for later use:

xinput list

Mine is: “Evoluent VerticalMouse 4”

Learn your mouse’s buttons’ positions

Install xev if not already installed:

sudo apt-get install xev

Open a terminal, and run xev from the command line. A small white window will open. Put your mouse in that window, and try clicking one of your mouse’s buttons. You will get a lot of output for every click. You need to find a block that looks like this, the most important part being near the end (button 3 in this case):

ButtonPress event, serial 36, synthetic NO, window 0x3c00001,
 root 0x269, subw 0x3c00002, time 14058208, (44,38), root:(1725,240),
 state 0x10, button 3, same_screen YES

Now you can easily write down the number associated to every button of your mouse.

Choose the right order for your buttons

We will use xinput to change the button mapping. Starting with the button map you have just written down, you can easily swap buttons to match your preferences. For example, here’s what I had at first (my mouse has three buttons like in the old times, and two thumb buttons) :

  1. Left click
  2. Middle click (paste selected text in Linux)
  3. Right click
  4. Wheel scroll up
  5. Wheel scroll down
  6. ?
  7. ?
  8. Upper thumb click (back)
  9. Wheel click (forward)
  10. Lower thumb click

Here’s what I wanted :

  1. Left click (1)
  2. Right click (3)
  3. Forward (9)
  4. Wheel scroll up (4)
  5. Wheel scroll down (5)
  6. ?
  7. ?
  8. Back (8)
  9. Paste selected text (2)
  10. Lower thumb click (unused… 10)

In my case, the xinput command looks like this:

xinput -set-button-map "Evoluent VerticalMouse 4" 1 3 9 4 5 6 7 8 2 10

You can run this command in the terminal to test if your configuration works well. You can always come back to default with :

xinput -set-button-map "Evoluent VerticalMouse 4" 1 2 3 4 5 6 7 8 9 10

Make your command run at startup

We’re almost done… Now create a file in your home directory with a name something like¬†.mouse_config, and paste your xinput command in it. Open the automatic startup program that comes with your OS. Its name in Ubuntu 12.04 is Startup Applications. Add a new entry that points to your script, add a name and a description if you want to, and that’s it! Enjoy a perfectly working mouse!