Table of Contents

Ubuntu - Mouse - Map Mouse Buttons

In most cases,



Map a Mouse Button to Another Button

This can be useful for changing the mouse for left-handed people.

xinput set-button-map 8 3 2 1 4 5 6 7 8 9

NOTE: The initial 8 is the Mouse Id as determined above.

  • The remaining 3 2 1 4 5 6 7 8 9 is the 9 mouse buttons as determined above.
  • Usually this would be in the order 1 2 3, where
    • 1: is the left mouse button.
    • 2: is the middle mouse button.
    • 3: is the right mouse button.
  • Here, button 3 is swapped with button 1.
    • This means that when the actual left button on the mouse is clicked it results in a right-click.
    • Also, clicking on the actual right mouse button results in a left-click.

Disable a Specific Mouse Buttons

xinput set-button-map 8 1 0 3 4 5 6 7 8 9

NOTE: The initial 8 is the Mouse Id as determined above.

  • The remaining 1 0 3 4 5 6 7 8 9 is the 9 mouse buttons as determined above.
  • Here, button 2 is replaced by a zero.
    • This disables this button.

Run at startup

One approach is to create a shell script that performs the Mouse Button mapping:

echo "xinput --set-button-map 21 3 2 1" > leftmouseremap.sh

Give it executable permission:

chmod +x leftmouseremap.sh 

NOTE: Either run the script manually, or configure it to automatically run on system reboot.

  • Follow any process to have this script run at boot if needed.
  • Remember to configure 'xbindkeys' to run automatically on system startup too if needed:
    • '/usr/bin/xbindkeys'

References

http://manpages.ubuntu.com/manpages/focal/man1/xev.1.html

https://linux.die.net/man/7/xautomation

https://manpages.debian.org/stretch/xautomation/xte.1