mouse sometimes doubleclicks when i click once

OK after extensive testing using xev on the affected machine, and switching around between various mice on various systems, I believe I have solved this problem. Of course YMMV.

My solution: it is a broken mouse.

More precisely, the connector activated when clicking is a bit old or dirty or something, and sometimes, when holding the button down, the connection is made, and then momentarily broken, and then made again, causing the double click.


Objection: But the mouse works fine when I plug it into my Windows machine!

Counter: Wouldn't it be just trivial to put into a driver, or an OS, the following line of pseudocode: "if the user unclicks the mouse and then clicks it again within 0.05 seconds, then that's probably a dirty connector, so let's just ignore that". Thus isn't it possible that if you switch your mouse to another computer running another OS and/or using another driver on different hardware (even with the same OS you could well be using different hardware, right?), you could get different results?

Objection: But I tried another old mouse and it exhibited the same problem!

Counter: amazing how two old mice from the same company can both break in the same way, eh? And you never noticed because that second old mouse you tried was exhibiting no problems when plugged into different hardware (see previous counter).


If you really don't believe your mouse is broken, then test it:

$ xev

and then find the square with the black background, click in it, and watch the output. Do you definitely, always, get one clean "click" and nothing else? I would often get a clean click but occasionally a "bounce "(click unclick click). Even better perhaps:

$ xev | grep ButtonRelease

Now stick the mouse into the square with the black outline (or anywhere in that window) and click and unclick 20 times. You should get a "ButtonRelease" line every time you release the button, and never otherwise. I would occasionally get one when I clicked.

Nightmare over.


Zen and mouse maintenance. Seems many are having a problem with the mouse double clicking when one click is applied. The mouse button is a micro switch. The fact of life is that switch contacts bounce. They don’t actually bounce but rub. We will call it bounce anyway. For some reason the programmers have dropped the ball on this one. A wait loop of sufficient duration should be applied for the contacts to settle before reading. Apropos of nothing and on a sample of one my solution has been to place a capacitor across the switch contacts. I used a 0.1uF cap for no particular reason other than I had one in a small size that would fit inside the mouse nicely. I haven’t done any fancy analyses of dwell time, time constants or decision levels to find an optimum value. Various models will have different parameters anyway.

I have been using this modification for some time and the problem hasn’t resurfaced so far.

To apply the mod. Find a capacitor of small physical dimensions that will fit inside to mouse case. I used a 0.1uF because I had one and it is a nice number but other values will probably work but don’t go too large or too small. What is too large or small is a matter for experiment. Too large may affect intended double clicks, too small won’t achieve the desired effect. I soldered one leg of the cap at a convenient location, where it didn’t run foul of the inside structure of the mouse, on the copper side of the board, to the 0 volt plane (earth plane if you wish) I hooked the other leg of the cap to the switch active with a bit of thin wire. I used a recycled component with short legs. A new one would likely have long enough legs to reach to where it is needed. You will need a suitable fine tipped soldering iron for the job.

If you don’t know capacitors. A 0.1uF capacitor may be designated 0.1uF or 104 or 100nF or have brown black yellow coloured bands. A surface mount type would be a good choice also. Hook it in with some strands of fine wire. Could glue it to the board connection side up.

I have a plan B which I may try next time or if the current plan eventually fails. Ditching the micro switch for a spst PCB mount tactile membrane switch should solve the problem. That is the type of switch used in keyboards and key pads and don’t exhibit this problem. The foot print it nothing like the micro switch. A switch 7mm high is available which will come in at the same height as the existing micro switch. A smaller switch would need to be spaced up to the correct height. Bend the legs at right angles to the switch body and glue it to the board so that the actuator aligns with the position occupied by the micro switch actuator. The mouse button has to hit the correct spot. Wire the switch contacts in with some fine wire and all should be good in theory.


I've built a patched xserver-xorg-input-evdev for Ubuntu 14.10. I used the instructions from http://blog.guntram.de/?p=16 (patch can be found here and here) and a Debian packaging manual.

Here are my notes about building a package.

#!/bin/bash
# http://blog.guntram.de/?p=16
#

apt-get build-dep xserver-xorg-input-evdev

dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"

wget --output-document=evdev-debounce.patch http://blog.guntram.de/?ddownload=20
apt-get source xserver-xorg-input-evdev

cd xserver-xorg-input-evdev-*

$dquilt new debounce.patch
$dquilt add include/evdev-properties.h src/Makefile.am src/debounce.c src/evdev.c src/evdev.h src/debounce.c
patch -p1 <../evdev-debounce.patch

$dquilt refresh
$dquilt header -e

debuild -us -uc -b
cd ..

sudo dpkg -i xserver-xorg-input-evdev_*.deb
  • Good news: it worked.
  • Bad news: it doesn't always help. My mouse button contact was so bad that it needed a 200ms delay, which stops me from double-clicking. Another bouncing mouse began working fine.

edit: Thanks @MatijaNalis, the patch obtaining steps could be:

wget https://aur.archlinux.org/packages/xf/xf86-input-evdev-debounce/xf86-input-evdev-debounce.tar.gz
tar xzf xf86-input-evdev-debounce.tar.gz
# ...
patch -p1 < ../xf86-input-evdev-debounce/debounce.patch

The problem, explained by Jack Ganssle, here: http://www.eng.utah.edu/~cs5780/debouncing.pdf
- contact bounce filtering. The software thingy needs to be there in any application, from simple single-board computers to operating systems, in some form.

https://www.google.se/?gfe_rd=cr&safe=off#q=%2Bcontact+%2Bbounce+%2Bsoftware&safe=off

As contacts / buttons get older, the effect will get worse. WD40 might not be the best spray to use on electronics, there are others more suiting. Google 'Contact spray'.


I had a problem with an additional button clicking twice. As I already had it mapped with xbindkeys (see How can I assign actions to all my mouse buttons? for more information on that) my solution was changing the entry in the ~/.xbindkeysrc as follows:

"if [ ! -e /dev/shm/button ]; then touch /dev/shm/button; /usr/bin/xte 'keydown Control_L' 'key Page_Down' 'keyup Control_L'; sleep 0.2; rm  /dev/shm/button; fi"
b:7

This creates a "lockfile" for every button press in /dev/shm/(which I hope lies on RAM) and removes it after 0.2 seconds. And the xte command shall be done on mouse click and shall not be done twice in 0.2 seconds.

(Just thought I'd share my solution, in case anybody want's to copy it or to fix it.)