Prerequisites

Note: These are helper comments, and can be ignored if you are looking for nothing but raw information. Due to community feedback, I decided to add a bit more commenting that describes what's going on "behind the scenes" with this configuration.

We will be using the evdev driver for Xorg. EVentDEVice is an advanced driver for USB input devices which offers much greater power over the standard Xorg mouse driver. It is also more "direct" than the mouse driver, allowing lower latency and less translation issues.

Note that evdev is both a kernel module and an Xorg input driver. All the Arch kernels come with the evdev module.

With the newer Xorg 11R7.0 it seems only the following changes to /etc/X11/xorg.conf need to be made with nothing else needing to be done.

Finding the mouse name

Note: To get accurate information it is sometimes required to execute this command from a boot where no Xorg or mouse drivers have been loaded.

The first step is to find the name of the mouse / mice. To do this, execute the following command:

Replace the Name option with the name you copied from above. You may also omit the CorePointer option if you use multiple mice or experience errors when attempting to load Xorg. The other options are all basic mouse configurations for evdev and should work with most mice.

Next, we need to tell X to use the mouse, so look in xorg.conf for ServerLayout.

Modify the ServerLayout section to use "Evdev Mouse" as the device. When you are done, it should look something like this:

Reason: The udev rule will not work, the SYSFS= and BUS= keys have been removed [1]. (Discuss in Talk:Mouse buttons#)

With a Desktop type keyboard-mouse, this does not work because there is only one USB attachment and /dev/input/by-id contains only the keyboard.
In this case, we can create a udev rule to get a consistent link.
The following rules create the link /dev/input/usbmouse which points on the correct event entry:

Thumb Buttons - forward and back

Note: The following maybe redundant depending on whether xev detects all your mouse buttons correctly (functions can be mapped on a per-app basis) or you want to change the default behaviour.

To do this we need to map keystrokes to the desired mouse buttons and install xvkbdAUR and xbindkeys.

In most modern applications which use back/forward features, XF86Back is mapped to back and XF86Forward is mapped to forward by default. On most MX mice the thumb buttons resolve to 8 & 9. If your mouse is different, check button numbers using xev and replace the numbers used in the example (b:8 & b:9).

So if you have an MX mouse you would create the file ~/.xbindkeysrc, containing:

Now to test... Run the following command and if it works as expected remember to add xbindkeys to .xinitrc or somewhere where it will be executed each time X starts. Also, this should work with Epiphany and Konqueror without any additional configuration or use of Imwheel.

xmodmap tweaking

Note: None of the below is necessary with evdev, but it's here for non-evdev users. Unless something does not work on your mouse, ignore this whole section!

If you use .xinitrc to load X, then add this to .xinitrc (change for the number of buttons you have):

xmodmap -e "pointer = 1 2 3 6 7 8 9 10 11 12 4 5" &

Note that buttons 4 and 5 must go on the end or else your scroll wheel will not work.

If you use GDM/XDM/KDM instead of .xinitrc, then create the file ~/.Xmodmap and add this to it (change for the number of buttons you have):

pointer = 1 2 3 6 7 8 9 10 11 12 4 5

GDM/XDM/KDM read the ~/.Xmodmap file if it's present, whereas startx does not. Another solution would be to add this to your ~/.xinitrc: xmodmap ~/.Xmodmap. This would allow you to use *DM and startx while only having to edit ~/.Xmodmap when you need to make changes.

You may have to play with these numbers a bit to get your desired behavior. Some mice use buttons 6 and 7 for the scroll wheel, in which case those buttons would have to be the last numbers. Keep playing with it until it works!

You can also check to see which buttons are being read with a program called 'xev', which is part of XOrg. When xev is run, it will show a box on your desktop that you can put the cursor into and click buttons to find out what buttons have been mapped.

xinput tweaking

For debugging purposes xinput can be used as it is able to change the button map on the fly in userspace. The following line corrects the button mapping (there have been reported cases with Logitech M505/B605 mice and possibly others) so the received events are mapped correctly:

Alternate methods

The following methods use standard X.org mouse input driver (xf86-input-mouse) instead of using the evdev driver. It works on mice up to 7 buttons. Edit /etc/X11/xorg.conf InputDevice section for your mouse to reflect the changes shown below. Then restart X and you are done.

IMPS/2

This has been tested on an IntelliMouse Explorer 3.0. Your mileage may vary, as this does not seem to work for all said mice.

easystroke

easystroke is a mouse gesture application, but it can be used to manage mouse buttons as well. Its main advantage over btnx is that it's more versatile. On the other hand, it's user-based, so any user has to configure it to reflect his own needs.

In order to set up easystroke to manage your extra mouse buttons, you will need to do this (example features Back/Forward mouse buttons) :
run:

Note: In case of easystroke does not automatically detect mouse buttons, you can specify it manually. Button identifiers (numbers) can be viewed by xev.

Go to Action tab > Add action, give the new action a name, as Type choose "Key", as Details set "Alt+Left" for Back button, "Alt+Right" for Forward button, as Stroke click the proper mouse button (confirm if a warning is displayed), and voilà! Your mouse button is configured.

Binding keyboard to mouse buttons

xvkbd and xbindkeys

Let us say we want to bind some mouse buttons to keyboard ones. The problem we will encounter is that we do not know how to emulate a key press. Here comes in handy xvkbdAUR. We can use it along with xbindkeys.

If you want to check your mouse buttons number use xev. Do not forget to type capital letters in xvkbd -text usage and to escape opening bracket with \ or you get simply [Shift] written.

Here is an example for xbindkeys to enable x selection paste(third click pasting), you need both xsel and xvkbd installed, What it does it executes that command whenever button 13 of the mouse is pressed (in ~/.xbindkeysrc) :

"xvkbd -no-jump-pointer -text "\D1$(xsel)" 2>/dev/null"
b:13

This is an example for a keybinding for Meta+M:

"xvkbd -text "\{+Super_L}m\{-Super_L}""
b:10

evrouter

Some programs, especially games, use different methods of reading input, so another program is needed: evrouterAUR.

For the evrouter command to be able to read the input devices, it will have to be run in the input group (or as root). This can be achieved by adding yourself to that group:

# gpasswd -a user input

Now we can use the --dump option to display what the button to be changed is called:

Tip: For USB devices udev will usually create symbolic links in /dev/input/by-id/ which can be used to refer to specific devices.

The 'event1' was changed to 'event*' in case udev gives it a different device number at boot. The 'none' was changed to 'any' so that the rule works even if any modifier keys are pressed when the button is pressed. To determine the key codes (in brackets) you can use

# xmodmap -pk

See evrouter(1) for a full explanation of the fields.

Tip: Rules can apply only to specific windows, see evrouter(1) for details.

After setting up the config file, run it as a daemon:

$ evrouter /dev/input/event*

To stop the daemon:

$ evrouter -q
$ rm -f /tmp/.evrouter*

Note:evrouter will fail to start if the /tmp/.evrouter:0.0 file exists but does not delete it when exiting, so you will have to delete it yourself.

Binding + and - in Logitech G5 mouse

If you want to bind the buttons + and - in G5/7 mouse, which normally changes DPI, you have to use g5hack[2] released by a lomoco author.

This will change your DPI to 2000, light the 1st LED and disables DPI on-the-fly changing, so you can use it with evrouter. If you would use it frequently I suggest you to copy it to the /usr/bin directory:

# cp g5hack /usr/bin/

If you want to bind your + and - buttons you must copy the line at the bottom (one with the comment '"-" button does not function anymore' above) to the mode you will be using, like, for example, under the "case 3:" you can put it on the line with the comment 'turn on third led' above (deleting the old one before of course).

For the newest G5 mouse which is reported as "product 0xc049" original hack does not work. You have to simply change the #define MOUSE_G5 0xc041 to #define MOUSE_G5 0xc049 and recompile.

lomocoAUR for Logitech MX mice will help you set the proper resolution, enable or disable smart scroll (with boot time support too!), etc. lomoco is available from the [community] repository and can be installed with the following command:

Be sure to look at /etc/udev/lomoco_mouse.conf and set up the the options you want to be automatically applied when the mouse gets loaded by udev.

Note: The lomoco package may be out of date. There is a hack for newer Logitech mice: [3]

Device Specific Configuration Files

Logitech G600

It is known that in xorg-server 1.18.0-3 side buttons of G600 are not recognized as a separate keyboard device, but another mouse which causes strange (moving mouse cursor to an edge of screen when one of main mouse buttons are clicked) behavior.
To force xorg to recognize them as a keyboard buttons, add following section to your /etc/X11/xorg.conf:

Mad Catz Mouse

Logitech M560/M545/M546

These mouse is designed for Windows 8, and has a non conventional behavior: the mouse appears as a pair of mouse and keyboard and some buttons don't emit the standard mouse button event, but instead a combination of keyboard and mouse button. This prevent a "confortable" use of this mouse under Linux.

This driver allow to use this mouse like an ordinary mouse. It's recommend use it with xbindkeys to mapping buttons.