Keyboards suck

Originally posted to Shawn Hargreaves Blog on MSDN, Wednesday, March 28, 2007

I'm not a hardware guy, but if I had to design a keyboard I'd probably include some kind of electrical switch under each key, with a set of wires leading to and from each switch so I could detect when they were pressed.

Bzzzt, wrong!

Real hardware designers reduce manufacturing costs by sharing only a few electrical connections between many keys. Next time you are throwing out an old keyboard, rip it open first and take a look inside. You'll see a crazy circuit board with a matrix taking voltage to and from the various switches, but if you look carefully, you'll notice the same inputs and outputs are routed to many different keys. How can this possibly work?

The trick is that in order to detect a single keypress, you don't actually need a unique wiring for that key. As long as each key has a unique combination of input and output connections, you can figure out things like "source #3 and destination #5 have voltage, so 'O' must be pressed".

You can also detect multiple keypresses, using logic like "sources #3 and #4 are connected to destination #5, which means both 'O' and 'K' must be pressed". In fact, any combination of two keys can be reliably detected (the proof of which I shall leave as an exercise for the reader).

More than two simultaneous keys, however, are a problem. Some combinations may work ok, but others will try to connect source and destination wires that are both already in use by other keys, in which case the new press will be completely ignored. Even worse, exactly which combinations can be detected varies from one keyboard to another, depending on the details of how their wiring matrix is laid out.

This behavior was fine for the word processing applications that keyboards were originally designed for, but is not so great for games. There is nothing we can do to fix the hardware, but there are a couple of ways we can minimize its impact:

Blog index   -   Back to my homepage