52

My mouse has an unfortunate feature. On the left side, right where my thumb sits ever so gently when I'm using it, there are two buttons that are so sensitive a mere brush will make them click.

I'm talking of course about the pesky forward/back buttons which, if pressed in a browser, can make watching that hour-long youtube video that much harder. Is there a way for me to disable them? Would this be handled by X?

n0pe
  • 9,411
  • 13
  • 60
  • 108

5 Answers5

63

Start the program xev in a terminal. Move the mouse inside the xev window; you'll see a lot of stuff scroll by. Press each button in turn. Then switch back to the terminal window and press Ctrl+C. xev shows a description of each input event, in particular ButtonPress and ButtonRelease for mouse clicks (you'll also see a number of MotionNotify for mouse movements and other events).

It's likely that your forward and back buttons are mapped to mouse buttons, maybe buttons 8 and 9:

ButtonPress event, serial 29, synthetic NO, window 0x2e00001,
    root 0x105, subw 0x0, time 2889100159, (166,67), root:(1769,98),
    state 0x0, button 8, same_screen YES

If that's the case, remap these buttons to a different action in your browser, if you can. Alternatively, you can remap the buttons to different button numbers which your browser doesn't react to or disable the buttons altogether at the system level. To do this, put these lines in a file called ~/.Xmodmap:

! Remap button 8 to 10 and disable button 9.
pointer = 1 2 3 4 5 6 7 10 0

Test it with the command xmodmap ~/.Xmodmap. Most desktop environments and window managers run this command automatically when you log in; if yours doesn't, arrange for it to run when X starts.

It's also possible that your mouse sends a keyboard event when you press these buttons:

KeyPress event, serial 32, synthetic NO, window 0x2e00001,
    root 0x105, subw 0x0, time 2889100963, (957,357), root:(2560,388),
    state 0x0, keycode 166 (keysym 0x1008ff26, XF86Back), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

In that case, put lines like these in ~/.Xmodmap:

keycode 166 = NoSymbol
keycode 167 = NoSymbol
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 4
    Thank you both for the question and the answer. Incidentally, to reduce the insanity of the `xev` output, just pipe it through grep: `xev | grep -A2 ButtonPress` ; this will leave all the mouse motion events, focus events, etc. and just show the `ButtonPress` events, which is all you need here. – Lambart Sep 19 '14 at 18:50
  • Thank you! It helped in a few seconds! :-) – Brian Cannard Dec 30 '18 at 02:33
  • This works in Wayland too! – Ray Foss Apr 16 '19 at 16:18
  • To disable in Firefox, open `about:config` and search for `mousebutton`. At least on my machine `mousebutton.4th.enabled` is the back button. Double click it to disable. – Tor Klingberg Jul 13 '21 at 09:38
  • @RayFoss Is there documentation to support this? My arch installation (KDE with Wayland) has neither the `xev` nor `xmodmap` commands. – nathanfranke May 25 '22 at 05:09
  • `X Error of failed request: BadValue (integer parameter out of range for operation` – Henrique de Sousa Jan 22 '23 at 21:20
  • @HenriquedeSousa Posting an error message without saying what caused it is a waste of both my and your time. But my crystal ball says you got the keycode or the number of mouse buttons wrong. – Gilles 'SO- stop being evil' Jan 22 '23 at 22:44
  • Sad that we're unable to edit comments. The error occurred when doing `xmodmap ~/.Xmodmap` and is (probably?) due the number of mouse buttons indeed. – Henrique de Sousa Jan 25 '23 at 12:12
8

just a quick command to fix it, not really different from other answers:

xmodmap -e "pointer = 1 2 3 4 5 6 7 0 0 0 0 0 0" #the fix

testing

xmodmap -pp # check the changes
xterm -e xev # test the nullified buttons

# to restore in case you are going to play some game that uses them
xmodmap -e "pointer = 1 2 3 4 5 6 7 8 9 10 11 12 13"

you can put the fix cmd at startup apps.

better would be to use xdotool to check if active window is any of your browsers and call xmodmap on demand to disable/enable'm, but that would require some scripting :>

I saw no reason to keep buttons above 7 enabled, any reason?

Aquarius Power
  • 4,099
  • 5
  • 38
  • 56
  • This works for me. It disables the "back" function which is annoying to me. Interestingly I am using a trackball mouse and I can still use this mouse button in combination with moving the ball to imitate "scroll" function. Used to be that scrolling triggers the "back" key which was annoying. – Yan King Yin Dec 18 '22 at 09:57
3

You could use xev to find which key maps the button maps to and use the code below (in $HOME/.xsessionrc) to map it to something you are not using.

xmodmap -e 'keycode THE_CODE_HERE = XF86Launch1'

Alternatively, you should be able to do that from a GUI of you use Gnome/KDE or any other modern desktops.

Yet another option would be to hack the xorg.conf to remove the button definitions.

1

If you are trying the xmodmap commands (on X, not Weyland) and you are getting the error BadValue (integer parameter out of range for operation) in X_SetPointerMapping, you may need to use xinput instead. Run xinput with no parameters to get the device IDs (look for one for the pointer) then run

xinput set-button-map [pointer-device-id] 1 2 3 4 5 0 0 0 0

In my case, my mouse was device #4 and I needed to make buttons 6 and 7 into 8 and 9 to get forward and back to work so I used

xinput set-button-map 4 1 2 3 4 5 8 9 8 9

(I kept buttons 8 and 9 also mapped to 8 and 9 in case I changed mice.)

DerfK
  • 339
  • 1
  • 7
0

Can be done with xorg config file

Here is an example that disable horizontal scroll (Save the new file and reboot)

nano /etc/X11/xorg.conf.d/40-libinput-mouse-left-right.conf

Section "InputClass"
        Identifier "Logitech catchall"
        MatchIsPointer  "on"
        Driver "libinput"
        Option "HorizontalScrolling" "false"
EndSection

Other useful commands

xinput list
xinput list-props 15

Now for this question xorg config file can be used to remap button here is an example

Section "InputClass"
    # ...
    Option "ButtonMapping" "1 9 3 4 5 6 7 8 2"
    # ...
EndSection
intika
  • 13,920
  • 7
  • 41
  • 79