Ubuntu – How do you disable middle mouse click even after restarting

mousereboot

I'm looking for a way to permanently disable middle mouse click on my Ubuntu 18.

In this post, @Yehosef kindly gives this solution to disable middle click:

xinput list #to find mouse id
xinput set-button-map [mouse id] 1 0 3

but I need to type it each time I restart my computer.

Is there a way to make it persistent?

Best Answer

This is what I do on Ubuntu 20.04 (uses Wayland by default) to disable my middle button or remap my middle button.

To find my device id:

$ xinput --list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ xwayland-pointer:17                       id=6    [slave  pointer  (2)]
⎜   ↳ xwayland-relative-pointer:17              id=7    [slave  pointer  (2)]
⎜   ↳ xwayland-touch:17                         id=9    [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ xwayland-keyboard:17                      id=8    [slave  keyboard (3)]

I had to do a couple test before I found the right id. For me, it was 6.

To see current button map:

$ xinput get-button-map 6
1 2 3 4 5 6 7 8 9 10 

To disable middle button:

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

To remap middle button to left click:

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

In order to run at startup, create a file and make sure it's executable (chmod a+x):

#!/bin/bash
xinput set-button-map 6 1 1 3 4 5 6 7 8 9 10

Ubuntu and other GNOME based distributions come with an application simply called “Startup Applications”. It can be used for managing apps and scripts that run on a fresh system reboot or login. So just do a search for it, open it and add the file you just created.

Related Question