Keyboards - The Three Key Problem

August 8, 2012

When developing your game and choosing default keyboard keys for the controls of your game, you may have noticed that certain combinations of keys can only be pushed at once. A lot of keyboards don't allow you to press certain combinations of more than two keys at the same time. I had forgotten about this and just recently, while working on my bullet hell shooter, I started out using the spacebar and arrow keys to get my player shooting and moving. I quickly noticed that I couldn't move my player to the upper-left while pressing the spacebar.

So first of all, why does this happen? Shouldn't I be able to use the spacebar with two other arrow keys? Seems crazy, right? There's a simple explanation for this. This isn't a problem with the programming language or API you're using. The problem is actually the keyboard itself, and it stems from a design decision so that manufacturers can cut costs making Keyboards. This is called Ghosting, and Wikipedia and Shawn Hargreaves both have good explanations about it, so no need for me to go into detail here.

So how do we fix it? There are better keyboards available that are tailored to gamers, but obviously you can't expect everyone who plays your game to go buy one. :) The best answer I've found is to provide a way for the user to configure the keys. Avoiding the keyboard entirely and only supporting a gamepad doesn't seem like a good idea. It took me a while before I hooked my gamepad up to my PC, and I'm guessing there's a lot of gamers still in the same boat.