Getting the ID of your mouse:
You can get it running xinput list
:
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ HID 046a:0023 id=9 [slave pointer (2)]
⎜ ↳ Logitech G9x Laser Mouse id=10 [slave pointer (2)]
⎜ ↳ Logitech G9x Laser Mouse id=11 [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)]
↳ Power Button id=7 [slave keyboard (3)]
↳ HID 046a:0023 id=8 [slave keyboard (3)]
I have two mouse IDs (10 and 11), therefore I have to test the right ID.
Swapping the buttons:
You can swap the mouse buttons running this (where 10
is the ID):
xinput set-button-map 10 2 1 3
You can revert the change with:
xinput set-button-map 10 1 2 3
Swap the buttons automatically when X starts:
Run this command to edit the 91swapmousebuttons file:
sudo nano /etc/X11/Xsession.d/91swapmousebuttons
Add this line to it:
xinput set-button-map 10 2 1 3
Explaination of the parameters passed to xinput:
set-button-map
changes the button map of a device.
10
is the device ID.
2 1 3
means:
2
: It's on the 1st position, so the first button (LMB) is mapped to button 2 (MMB).
1
: It's on the 2nd position, so the second button (MMB) is mapped to button 1 (LMB).
1
: It's on the 3rd position, so the third button (RMB) is mapped to button 3 (LMB).
Note that LMB is Left Mouse Button, MMB is Mid Mouse Button and so on.
Quote from man xinput
:
Change the button mapping of device. The buttons are specified in
physical order (starting with button 1) and are mapped to the logical
button provided. 0 disables a button. The default button mapping for a
device is 1 2 3 4 5 6 etc.
xinput list
to your question.