Disabling middle mouse button

So I tried looking through the various other questions but they mostly focus on disabling the middle mouse paste.

Basically the middle mouse button on my Logitech G500s is broken, and it keeps "clicking" randomly so it's screwing up any chance of doing work.

Is there any way to disable it? Or map it to nothing?

Thanks and sorry if this is a duplicate.

xinput list output:

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜   ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜   ↳ Turtle Beach Turtle Beach PX3 (XBOX) id=8 [slave pointer (2)]
⎜   ↳ Logitech G500s Laser Gaming Mouse id=9 [slave pointer (2)]
⎜   ↳ Logitech G500s Laser Gaming Mouse id=10 [slave pointer (2)]
⎜   ↳ Razer Razer DeathStalker id=12 [slave pointer (2)]
⎜   ↳ Razer Razer DeathStalker id=13 [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)]
    ↳ Razer Razer DeathStalker id=11 [slave keyboard (3)]

Execute those commands:

xinput set-button-map 9 1 0 3
xinput set-button-map 10 1 0 3

Explanation (kindly donated by @Yehosef):

The first number is the identifier of the pointer (you'll often only have one, in this case there were two, 9 and 10).

The next numbers are what you do with the first, second, and third (ie, left, middle, right) mouse buttons. 1 0 3 tells it that the left button should do a left click (action 1), the middle button should do nothing, and the right button should do a right click (action 3). If you want to make the middle button also do a left click you could use 1 1 3. If you wanted to switch the right and left actions you could use 3 0 1. See https://wiki.ubuntu.com/X/Config/Input for more info.


Following instructions are based on info at Ubuntu Wiki (Scroll down to title "Example: Disabling middle-mouse button paste on a scrollwheel mouse").

First, determine id of the pointer by listing input devices:

xinput list | grep 'id='

And look for the line that contains name of your pointer, there also should be id of the device, right after "id=". For example, id of this device is 10:

Lenovo ThinkPad Compact USB Keyboard with TrackPoint    id=10   [slave  pointer  (2)]

Next, get current button map of that device (I'll be using id of my device, which is 10):

xinput get-button-map 10

Output:

1 2 3 4 5 6 7 8 9

This is mapping of pointer buttons to actions, where number represents action code, and position - button.

We're interested in second map - number 2 corresponds to action "Middle Button Click" and the position of it - to actual middle button.

To disable middle button triggering any action, I'd use command xinput set-button-map with id of the device and updated map (new action code is 0 - no action). No need to put whole map - map till interested button suffice (the rest just won't be updated):

 xinput set-button-map 10 1 0

That's it.


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.