Keyboards suck

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:

  • Prefer the shift, alt, and ctrl keys, because these usually have dedicated wiring that will not cause conflicts.
  • Avoid game designs that require pressing many keys at the same time.
  • Avoid the keyboard entirely. Gamepads don't have this problem!

Comments (3)

  1. Gamepads, like keyboards , are not perfect. They are designed to be cheap, sturdy, and nice to hold:

  2. Sharky says:

    Shawn, I feel your pain!

    You’ve just explained why I was getting some very strange behaviour testing my game’s 2 player multiplayer keyboard support (awkward, but necessary for the broader audience that don’t own controllers).

    I was finding any time the user pressed V & B together, the A key failed to register (W, S & D keys too). Was too bad if you were trying to shoot, throttle and turn left at the same time!  I ended up changing the controls slightly so you’d use B & N instead and it all works fine – on my keyboard at least!

    On a related note, is there anyway of locking the NumLock state?

    See this post…




  3. Ultrahead says:

    "Avoid the keyboard entirely. Gamepads don’t have this problem!"

    I like this option, but then again "Gamepads suck" 🙂

Skip to main content