Hey, I’ve been using linux on and off for about 1 month (Started with Manjaro but I like Endeavour more) and I was wondering how to completely disable the middle mouse button. My middle mouse button is currently broken and everytime I scroll it activates the paste (which is annoying) but my mouse works fine so I don’t want to replace it. I just want to completely disable it entirely if possible. Please and thank you.
You need to remap the middle mouse button to something else. And this can be done in several different ways (depending on the display server you use). For now, I’m going to assume that you are using X11.
First, you need to find out the name of your mouse device:
virtual core pointer, you should see the name of your device as well as its device id. Take note of those two values. Next, find out the current button mapping of the device with:
$ xinput get-button-map 'device_name'
You should get something like this:
1 2 3 4 5 6 7
The idea is to remap the second button to nothing (0) or something that doesn’t exist (like 25). For example, to turn off middle pasting, you can change the current mapping to
1 0 3 4 5 6 7.
Here are a few ways to do this on X11.
Method 1: From the command line
On the command line, run
xinput set-button-map [your_mouse] 1 0 3 4 5 6 7.
[your_mouse] can be substituted with either the device name or the device id. To make this permanent, this command can be included in the startup scripts for your desktop environment.
Method 2: With Xmodmap
Inside your home directory, create the file
~/.Xmodmap. Inside that file, add this line:
pointer = 1 0 3 4 5 6 7
You’ll have to reboot/logout before the change can take effect.
Method 3: Use Xorg configuration files
Create the file
/etc/X11/xorg.conf.d/disable-middle-paste.conf and add the following content:
Section "InputClass" Identifier "Mouse Custom Configurations" MatchProduct "add your device name" Driver "libinput" Option "ButtonMapping" "1 0 3 4 5 6 7" EndSection
Reboot for changes to take effect.
What do those little numbers mean? Well, in
X11 the semantics for each button number is predefined.
0 = nothing 1 = left button 2 = middle button (pressing the scroll wheel) 3 = right button 4 = turn scroll wheel up 5 = turn scroll wheel down 6 = push scroll wheel left 7 = push scroll wheel right 8 = 4th button (aka browser backward button) 9 = 5th button (aka browser forward button)
A mapping is formed when you associate each physical button with one of these number codes. For example,
3 2 1 means to associate the left physical button with function 3 (right click) and the right physical button with function 1 (left click), essentially swapping the left and right buttons.
1 0 3 means to map the middle button to nothing.
Sorry for the late response, but unfortunately I am currently using wayland with KDE. Is there an xinput version for wayland sessions?
I’m not familiar with Wayland, so I’m not sure if there are any tools that provide this feature for Wayland sessions. The only other option I can think of right now is to define a new udev rule to disable the mouse button. More specifically, you have to create a hardware database file to define those rules.
The first step is of course to find out all the parameters required to define the rule:
- The name of your mouse. I’m not exactly sure how to do this on Wayland, but maybe you can try
libinput list-devicesand see what it returns. For the sake of this discussion, let’s assume that your mouse device’s name is Logitech ABC123
- The button press events as well as the scan codes. On Wayland, I believe you can obtain this information using
After that, you navigate into
/etc/udev/hwdb.d/ and create a file called
90-remap-mouse-middle-button.hwdb. Inside that file, include something like:
evdev:name:Logitech ABC123: * BTN_MIDDLE=reserved
I’m not 100% sure about the syntax for the
hwdb file here, so you probably have to look up a manual to be sure.
If you’ve defined the rules correctly, the change should take effect after a reboot.
I tried for a while and found the best solution was to set up a KVM Virtual Machine for windows 10 and then disable the input for middle mouse click altogether through Logitech G Hub. While it does suck that I have to do that, at least my problem is fixed. Thank you for your time and apologies for a late response.
I’m not sure about completely disabling the button altogether, but the ArchWiki has a note about disabling middle-click paste if it helps:
The following changes middle-click copy-pasting behavior from PRIMARY, without disabling middle click or altering its other functionalities, like opening in a new tab or scrolling, etc.
Run the script
#!/bin/sh while true; do xsel -fin </dev/null done
Using sxhkd, add the following to the configuration file:
button2 echo -n | xclip -in
So the udev rules didn’t work? That’s strange.
Regardless, I think I can come up with a few alternative solutions that are perhaps a tad more practical than your current one:
- Switch to X11.
- Install a front-end tool that supports wayland like
- Just get a new mouse? The mouse is surely old enough to have a malfunctioning button, so it might be worth investing in a new one (if for nothing else other than to save you some grief)
Honestly the 3rd option seems the best but that will be a future investment. I prefer Wayland as I use 2 monitors (144 and a 60hz) and it feels a lot smoother to me. I will try xinput via x11 later but I am okay with my current setup and will most likely just purchase a new mouse (this G502 has been through hell). Thank you for your time boss.