Skip to main content

Hacking Your Mouse To Fix The Misclick Of Doom

Debouncing SPST Switches

Not all mice use SPDT switches. Even when they do, all of the ones I've seen only used them as single-throw, or SPST. These are more difficult to debounce reliably since the switch can only be open or closed. There is no positive confirmation that the switch has fully released after closing (return to NC contact) to disambiguate between poor contact, the switch being in-flight or fully open. You only ever know when it closes with good enough electrical contact. Because of this, the only way to determine if the switch has indeed opened is to implement some sort of timer.

In software, programmable logic or integrated circuits, the SPST debouncing flowchart may look something like this:

You poll the input until you obtain a certain number of consecutive samples of the opposite state before accepting the new value as good. In this example, the input would need to be stable for four samples before its new value would get committed to the debouncer's output and if the process gets evaluated at a rate of 1000 iterations per second, this would introduce at least four milliseconds of input latency, more depending on how many bounces end up resetting the counter. Since there is no uncertainty surrounding a 'make' event, you can omit debouncing that transition to reduce input latency there and focus debouncing on the break event (just make sure your reset count is long enough to cover the longer break on that first bounce).

Where hardware implementations are concerned, options are quite limited. They all boil down to some sort of RC or RCD timing/filtering circuit along the lines of the circuit below.

Image 1 of 2

Image 2 of 2

Don't mind the low resistors and high capacitor values, those are simply necessary for getting the TTL chip to play along for this demonstration.

In this circuit, the capacitor charges whenever the switch is closed and discharges the rest of the time. The two resistors and the diode provide roughly symmetrical charge and discharge timing with a time constant of about one millisecond. As before, the Schmitt trigger buffer provides hysteresis on the capacitor voltage. Since the switch can only force voltage one way, high in this example, it is not possible to use the memory trick from earlier.

There are fancier circuits using opamp integrators for linear slope timing, comparators for wider hysteresis thresholds, asymmetric designs for faster propagation of a 'make' event and so on, but they all rely on the same fundamental principles as the circuit above. As-is, the circuit adds approximately one millisecond of input latency between the first bounce and debounced output. Not bad, but nowhere near as good as memory and SR debounce with SPDT switches, which provide immediate glitch-free detection, and Schmitt/memory debounce, which performs much the same.

Can you sense where I am going with this? The cleanest fix for a mouse with ailing buttons, short of replacing the whole mouse, is to put in new switches. You're good to go for a few more years until they start glitching too. The other option would be to look into wiring in a debounce hack, possibly of the SR variety.

Why bother repairing a mouse? I suppose you could say sentimental value. Again, I used to love this thing. Having input device diversity also helps reduce the risk of repetitive strain injuries. Of course, I could just chuck it into my spare bin and buy one of the newer and cheaper fingertip-operated models, which would have the added benefit of sparing my thumb. Another reason, as you may have guessed based on my previous repair stories, is that I despise throwing out stuff that fails for dumb and completely avoidable reasons. More importantly, it's good practice for when my G500S fails.

  • Rheotome
    I'll never look at a Mouse the same way after reading this !!!
    Reply
  • SirGCal
    My problem with my MS is just finding a mouse I can use well period.I have some mice like this trackball myself and still can't use it properly. I need one controlled with the mind instead of hand. Which is probably coming sooner then we think.
    Reply
  • mrface
    This is a really cool article. Thanks for sharing.
    Reply
  • theaudiophile
    Holy shit, you're crazy in many many ways. I am an electronics hobbyist myself, and you sir are simply insane. I hope this article gets enough traffic and ad clicks to make up for the time you put in instead of replacing switches.
    Reply
  • mikesinner
    Both me and a friend of mine have already bought new mice, but I did keep the old one, a logitech G700 with the terribly annoying double click glitch when only single clicking. It's not a very old mouse either, so I find it very disturbing that the switch is already worn!
    Reply
  • Daniel Sauvageau
    17690562 said:
    Holy shit, you're crazy in many many ways. I am an electronics hobbyist myself, and you sir are simply insane.
    You give me too much credit. This is a simple hack once you know what you are dealing with - finding out what you have to work with is usually the most tedious part of a modification job, especially when you don't have design schematics or someone else's instructions to start from.

    The hack might be more trouble than it is worth but it does show that there is no reason for mouse buttons with SPDT switches to glitch until the switch mechanically fails. Other than mice manufacturers choosing to design them this that way that is.

    17690678 said:
    Both me and a friend of mine have already bought new mice, but I did keep the old one, a logitech G700 with the terribly annoying double click glitch when only single clicking. It's not a very old mouse either, so I find it very disturbing that the switch is already worn!
    My G500S is about four years old and the glitching is at that early stage where I'm not sure if the glitches are caused by the mouse or by mouse movement when I click.
    Reply
  • BulkZerker
    http://www.epicpants.com/t-shirts/tek-syndicate-gaming-mouse-standard-issue


    Problem solved.
    Reply
  • razor512
    Wouldn't it be easier to just use hall effect switches (like with some industrial machines)?

    The switches can be magnetically shielded, and as long as the button actuation functions (no broken springs), the button will continue to work, along with any vibrations of the actuation being calibrated out in software.
    Reply
  • buzzrattie
    Wish there were a mouse that was cat-hair proof. Dang little buggers shedding all the time, and getting into the laser.
    Reply
  • Daniel Sauvageau
    17691040 said:
    Wouldn't it be easier to just use hall effect switches (like with some industrial machines)?

    The switches can be magnetically shielded, and as long as the button actuation functions (no broken springs), the button will continue to work, along with any vibrations of the actuation being calibrated out in software.
    I doubt switches that require additional calibration steps would be popular in a market where manufacturers are trying to optimize every penny of profit they think they can get away with out of their product.

    One option which does not require calibration is optical sensing: poke a slotted stem through the detector. Most mechanical mice used optical wheel encoders to convert ball motion to digital. The same thing could be done for switches.

    I doubt either option would be as inexpensive as a mechanical switch and with the "memory" version of my hack, it would be a practically free fix. Free is a tough price to beat.
    Reply