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.

Daniel Sauvageau is a Contributing Writer for Tom's Hardware US. He’s known for his feature tear-downs of components and peripherals.