How to completely disable the middle mouse button?

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:

$ xinput

Under 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.

Extra:

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.

6 Likes