1. Overview

The middle mouse button, also known as the scroll wheel button, is used for several purposes, including scrolling, pasting content from the clipboard, and opening links in a new tab. However, accidental clicks might trigger unintended actions and slow down the system. Therefore, we can prevent unintentional clicks that disrupt workflows by disabling the middle mouse button click.

In this tutorial, we’ll explore three methods in Linux to disable the mouse middle button click.

2. Using xinput

xinput is a powerful command-line tool in Linux. It provides the utility to list all the input devices connected to the system. Furthermore, using the xinput tool, we can extract information about the input devices and change their settings.

We can use the apt command to install the xinput tool in Debian-based systems from the Linux terminal:

$ sudo apt-get install xinput

After executing the command, let’s check the installation status of the xinput tool:

$ xinput --version
xinput version 1.6.3
XI version on server: 2.4

Thus, we can see that the xinput tool has been successfully installed.

Now, let’s run the xinput tool to see all the input devices connected to the system:

$ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=9	[slave  pointer  (2)]
⎜   ↳ VirtualBox mouse integration              id=10   [slave  pointer  (2)]
⎜   ↳ ImExPS/2 Generic Explorer Mouse           id=12   [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)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Power Button                            	id=8	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=11	[slave  keyboard (3)]
    ↳ Wireless hotkeys                        	id=13	[slave  keyboard (3)]
    ↳ HP WMI hotkeys                          	id=14	[slave  keyboard (3)]

To disable the mouse middle button click, first, we need to know the unique identity number of the mouse. In this case, as output displays, the ID number of the mouse is 12.

The next step is to get the button map of the mouse. The button map represents the logical button assignments for the physical buttons present on the mouse. We can extract the button map of the mouse by using the get-button-map option followed by the ID number:

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

Here, the ID number 2 in the button map result represents the middle mouse button. Therefore, to disable the mouse middle button click, we can replace the ID of the middle mouse button with 0 using the set-button-map option. Along with the set-button-map option, we provide the ID number of the device and modified button map:

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

Now, let’s verify the changes that we made in the button map:

$ xinput --get-button-map 12 
1 0 3 4 5 6 7 8 9

Thus, we can notice that button ID 2 has changed to 0. Hence, it indicates that the mouse middle button click has been disabled successfully.

3. Using xbindkeys

An alternative method for disabling the middle button click of a mouse is to use the xbindkeys tool. We can use it to customize the behaviour of the keyboard and mouse in Linux. Additionally, using the xbindkeys tool, we can bind custom actions to mouse buttons.

To use the xbindkeys tool, first, let’s install it in the system using the terminal:

$ sudo apt-get install xbindkeys

Before proceeding further, let’s verify the installation status of the xbindkeys tool:

$ xbindkeys --version
xbindkeys 1.8.7 by Philippe Brochard

After the successful installation, we create a configuration file for the xbindkeys tool:

$ xbindkeys --defaults > ~/.xbindkeysrc

The configuration file contains key and button bindings. We can customize the behaviour of input devices by changing the key and button bindings. Furthermore, we use the nano editor to open and modify the configuration file:

$ nano ~/.xbindkeysrc
# xbindkeys configuration #
###########################
# Version: 1.8.7
 To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
# List of modifier:
#   Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll).
# The release modifier is not a standard X modifier, but you can
# use it if you want to catch release events instead of press events
# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.
#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable
# Examples of commands:
"xbindkeys_show"
  control+shift + q
# set directly keycode (here control + f with my keyboard)
#"xterm"
#  c:41 + m:0x4
 specify a mouse button
#"xterm"
#  control + b:2
#"xterm -geom 50x20+20+20"
#   Shift+Mod2+alt + s
...output truncated...

In particular, to disable the middle button click of a mouse, we add an instruction in the configuration file:

"echo Middle button click disabled"
   b:2

After modifying the configuration file, we save the file and exit from the editor. Finally, to reflect the changes, we restart the xbindkeys tool using the -p option:

$ xbindkeys -p

Now, we’ve successfully disabled the middle button click of the mouse.

4. Using xmodmap

xmodmap is similar to the xbindkeys tool that allows us to modify keymaps and pointer button mappings. It’s a pre-installed tool part of the x11-server-utils package in Debian-based Linux systems. However, if we encounter errors while opening the xmodmap tool, we can install the x11-server-utils package from the terminal:

$ sudo apt-get install x11-xserver-utils

Now, let’s check the installation status of the xmodmap tool:

$ xmodmap -version
xmodmap 1.0.10

Furthermore, we create a configuration file for the xmodmap tool and edit it with the nano editor:

$ nano ~/.Xmodmap

Now, we add an instruction to the configuration file to disable the middle button of the mouse:

pointer = 1 0 3 4 5

The pointer indicates the button map of the mouse. Typically, the pointer 2 refers to the middle button of the mouse. Hence, by setting 0 in the place of the middle button pointer, we can disable the middle button click of a mouse.

Furthermore, to reflect the changes, we need to run the configuration file:

$ xmodmap ~/.Xmodmap

Finally, it’s important to note that we must re-run the configuration file every time we create a new session.

5. Conclusion

In this article, we discussed three ways to disable the mouse middle button click in Linux.

The xinput tool provides information on all the input devices connected to the system. Hence, we can configure the behaviour of any input devices using the xinput tool.

On the other hand, xbindkeys is very similar to the xmodmap tool. Both can be utilized to modify the behaviour of mouse buttons, including disabling the middle button click. However, the xbindkeys tool is more user-friendly than the xmodmap tool, as we can directly insert custom instructions in the configuration file.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.