Remapping mouse buttons

By | 9 Feb 2009

permanently

To remap mouse buttons permanently, you can use the xinput set-button-map command. Every mouse button click issues a button click with a specific id to X11. X11 recognizes the following buttons:

IDButton
1Left click
2Middle click
3Right click
4Wheel up
5Wheel down
6Wheel left
7Wheel right
8Thumb1
9Thumb2
10ExtBt7
11ExtBt8

You can use the following command to remap the buttons:

xinput set-button-map <device-id> <button1> <button2> <button3> … <buttonN>

The <device-id> is shown in the xinput list output – you can use the name as a string or the id number. You can query the actual button state using xinput query-state <device-id>.

So the default configuration (xinput set-button-map <device-id> 1 2 3 4 5 6 7 8 9) would give you the normal behavior. But if you prefer e.g. having the thumb buttons for WheelLeft and WheelRight, you would run this command:

#                       input id: 1 2 3 4 5 6 7 8 9
xinput set-button-map <device-id> 1 2 3 4 5 8 9 6 7

This would map buttons 8→6 and 9→7 and vice versa.

To automatically set your preferred mapping on bootup, you can add the line to SystemPreferencesStartup Applications (formerly Sessions).

per application (Wheel/Thumb only)

To remap wheel-/thumb-mouse buttons per application, you can use imwheel from the same-named package. After installing the package, copy the default configuration to your homedir:

cp /etc/X11/imwheel/imwheelrc ~/.imwheelrc

And then enable the automatic starting upon start of X11 by editing /etc/X11/imwheel/startup.conf and changing the IMWHEEL_START value to 1.

Now you can modify your .imwheelrc to fit your needs. The format is

"window regexp"
Modifier, Mousebutton, Keypresses/Mousebutton
…

So for example to use the WheelLeft and WheelRight buttons to switch tabs in Firefox, you could use the following definition:

"^Firefox-bin$"
# Flip between browser tabs
None, Left, Control_L|Page_Up
None, Right, Control_L|Page_Down

This would map WheelLeft to CtrlPgUp and WheelRight to CtrlPgDn.

A Modifier of None means, this only works if no modifier (Shift_L, Shift_R, Control_L, Control_R, Alt_L, Alt_R) is pressed while clicking. If you leave this empty, the mapping works regardless of which modifier is held down.

Use this to go to previous/next track in Rhythmbox using the WheelLeft and WheelRight clicks:

"^Rhythmbox$"
None, Left, Alt_L|Left
None, Right, Alt_L|Right

(In this case, Rhythmbox defines the window resource name since Rhythmbox itself puts the currently playing song in the title bar. You could also match against rhythmbox which is the window class name. Since imwheel -c wasn’t able to show them to me, I just guessed.)

2 thoughts on “Remapping mouse buttons

  1. andyb

    is it possible to simulate a double click? Can you whip up a script to convert a particular button press into a 2 left clicks?

    Reply
  2. negora

    There is an utility called “xprop” that allows you to click on a window and extract a lot of information. It’s useful to know the class name of it. I’ve needed to use it in Ubuntu and Linux Mint because “imwheel -c” seems to be broken.

    There’s also “xev”, which shows information about the keys pressed in the keyboard and the mouse. Useful to know the “keysyms” that you need in the imwheel’s configuration file.

    Reply

Leave a Reply