32

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)]
P.-H. Lin
  • 2,824

6 Answers6

33

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.

0x2b3bfa0
  • 8,780
  • 6
  • 36
  • 55
  • 1
    Thanks! For those wondering - the 9/10 are the input id of the mouse and the 1 0 3 are the mappings for the first, second, and third mouse buttons. If you wanted all buttons to do the same thing you could use 1 1 1 or if you want to switch the right and left buttons you could use 3 0 1. – Yehosef Jul 26 '16 at 08:03
  • @Yehosef: Thanks! I did not explain what is happening when the OP ran the commands. Please create a new detailed answer, ping me and I'll upvote. This is an interesting explaination. – 0x2b3bfa0 Jul 26 '16 at 20:13
  • @Helio I don't have a different answer - just more explanation for those interested. Perhaps you want to edit your answer to include this info you can. I was thinking about editing your answer - but I generally don't like it when people add extra details to my answers - so I refrained :) – Yehosef Jul 27 '16 at 11:15
  • @Yehosef: Feel free to edit my answer. However, would be great if you create a new answer instead. Even if it will not be accepted, it will be the better one. Another thing I could do is set mine as community Wiki. – 0x2b3bfa0 Jul 27 '16 at 15:12
  • I expanded your answer - obviously feel free to edit/remove. I appreciate your suggestion to make a new answer - but I think you successfully answered the question. Having a second answer that was the same but with more details would, IMO, be a worse stackoverflow experience. – Yehosef Jul 27 '16 at 21:20
  • 3
    So how do I determine the first number. I run xinput list | grep 'id=' and look for the things that looks most like my mouse/touchpad? Any definitive way of telling whether it is the right one? – Kvothe Jul 24 '18 at 21:15
  • @Kvothe: The only mean I know is by reading the output of xinput list and figuring out by flair which identifier os the good one. Maybe asking Cthaeh? – 0x2b3bfa0 Jan 30 '19 at 16:46
  • Thank you so much! For me, the 9/10 had to be a 4. I kept getting "device has no buttons" feedback in my terminal, so I just went down the line from 9 towards 0 until it worked, and vwalla! Now I'm no longer accidentally closing webpage tabs when I mean to click on them with my laptop's touchpad. You're awesome! Thank you! – user3330273 Jun 03 '20 at 13:08
18

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.

Be Kind
  • 473
  • This worked for my touchpad on a Lenovo Thinkpad T580 with Ubuntu 18.04 – Russell England Apr 24 '19 at 08:34
  • 3
    I think this answer is more thorough as it's important information to be able to get the id number of the input device. Otherwise, you're just randomly changing device settings. – Eric Streeper Jun 05 '20 at 22:15
  • Also - if you don't want the middle third of the click area to perform no action, you might want to consider setting it to left-click, so the left two thirds perform a left click, like xinput set-button-map X 1 1 – ACK_stoverflow Oct 22 '20 at 01:58
8

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.

chimeraha
  • 505
  • 6
  • 13
  • Thanks! Let me just add that if you want to be sure the middle button is the 2nd one - run xinput --list 6 | grep "Button labels:", and it'll list the buttons in order (e.g. Button labels: "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right"). As you can see in this case the middle button is indeed the 2nd. – Ezra Steinmetz Feb 20 '22 at 14:46
2

For Ubuntu 22.04, I stumbled across a related Q&A for Input Remapper.

Either:

  1. Search for Input Remapper in Ubuntu Software:

ubuntu-software-search-for-input-remapper

Or

  1. sudo apt install input-remapper

Which installs a GUI app:

ubuntu-show-apps-search-remap

It's perhaps a bit too highly configurable, though I figured out how to choose my Device (Logitech MX Master 3), click new entry, click Change Key, press the mouse wheel / Button MIDDLE, type disable, make sure the dropdown was mouse, and click Apply pretty quickly.

Toggle the Autoload to make it persist after reboot:

input-remapper-disable-middle-mouse-button

P.S. I used to use another xinput-based answer though this has completely replaced my need for it (not sure if Input Remapper is doing xinput under the hood or has truly got a Wayland version working, if so that'd be awesome!)

pzrq
  • 291
  • Thank you very much, this solution worked for me for disabling the very annoying middle click of the Apple Magic Mouse (1st gen) on an Ubuntu 22.04 installation on a mac mini (late 2012). – TheVRChris Mar 22 '24 at 16:45
0

set-button-map disables middle click functionality. To emulate middle-click using left+right click (so you can paste and open-in-tab etc using the mouse) but disable mouse wheel clicks, you can patch libinput:

--- a/src/evdev.c   2019-09-22 17:15:13.498880044 +0300
+++ a/src/evdev.c   2019-09-22 17:15:18.062860221 +0300
@@ -1861,6 +1861,8 @@
    /* Logitech Marble Mouse claims to have a middle button */
    if (device->model_flags & EVDEV_MODEL_LOGITECH_MARBLE_MOUSE)
        libevdev_disable_event_code(device->evdev, EV_KEY, BTN_MIDDLE);
+
+   libevdev_disable_event_code(device->evdev, EV_KEY, BTN_MIDDLE);
 }

 static void
  • mkdir deb; cd deb; apt source libinput; sudo apt build-dep libinput
  • save the above patch as libinput-1.XX.Y/debian/patches/middle.diff
  • add middle.diff to debian/patches/series
  • dpkg-buildpackage -us -uc -b
  • sudo dpkg -i ../libinput10_*.deb
  • restart Xorg or restart the machine

And use xinput list and xinput set-prop 11 "libinput Middle Emulation Enabled" 1 to enable the left+right emulation. 11 is the device number from xinput list and you can add the set-prop command to ~/.xstartup.

Or, to to avoid rebuilding, use a libinput .quirks file (untested):

[My Mouse]
MatchUdevType=mouse
AttrEventCodeDisable=BTN_MIDDLE;
patraulea
  • 681
0

GNOME Disable Middle Click

You can disable it with GNOME Tweaks.

First install it if you don't have already installed. Add the necessary repository:

$ sudo add-apt-repository universe

Then install:

$ sudo apt install gnome-tweak-tool

Finally, open it from the GNOME launcher (or from the console with gnome-tweaks), go to the Keyboards & Mouse tab, then in the Mouse Click Emulation section click the option Fingers. Optionally if you also want to disable the middle click for pasting in the console (at least for me is really annoying), in the same tab disable Middle Click Paste.

  • 2
    I could follow your steps, but it still past with middle-mouse button. – Adrian Maire Nov 30 '21 at 14:17
  • 1
    This will only disable the paste in GSettings, not the button itself. So in apps like Chrome that don't follow GSettings it'll still paste when you click the middle button. – Ezra Steinmetz Feb 20 '22 at 14:49