More Than Two Simultaneous Key Presses and KeyboardEvent.KEY_DOWN Woes

May 12th, 2008 | by Matt |

I'm rather annoyed right now. For whatever reason, I didn't think that determining if the user has 3 keys pressed at once would be so difficult. Attempt to press all the arrow keys that correspond to the arrows being displayed...

Sometimes it works, sometimes it doesn't and I can't understand why or find a pattern to the malfunction. But basically whats happening is at some point the KEY_DOWN event just isn't dispatched for a particular arrow key once two of the other arrow keys have been pressed. Does anyone have any freaking idea why this is happening?

  1. 7 Responses to “More Than Two Simultaneous Key Presses and KeyboardEvent.KEY_DOWN Woes”

  2. Definitely noticed this before with flash games.

    Up Down Left doesn’t work, nor does Up Left Right.

    Ash on May 12, 2008 | Reply

  3. The problem comes from the way in which the signal for the pressed keys moves from your keyboard to your computer. The signal is only 8-bit, and there are limits to how the signal can be changed to represent more than one key being pressed in combination.

    Long story short, the guys who designed the origional keyboards made a descision to support all two key combinations, and then selected as many three key combinations as they could support with the hardware. This meant that some combinations had to be left out, and they had to make a descision about which ones were more important.

    It just happens to be that they chose not to support three key combinations which involve the up arrow key. I do not think there is any solution to this problem…

    Tony Fendall on May 12, 2008 | Reply

  4. I tried this on my laptop over the weekend and was only able to get all three keys at once a couple of times. I just tried it on my desktop though and I was able to get all three keys almost every time. Im wondering if it has to do with the keyboard itself or the keyboard driver. Im using a dell keyboard that’s about 5 years old.

    Josh Dobbs on Jun 9, 2008 | Reply

  5. There is also a difference betweeen keyboard models.

    I discovered this when developing a racing game where we used a combination of space bar, left key and up all had to be pressed to accelerate, turn and jump all at once.

    Microsoft keyboards worked fine, Dell keyboards did not.

    You cannot achieve acceleration, and jump during a turn on the Dells, putting some players at a disadvantage.

    Clint on Jun 9, 2008 | Reply

  6. By the way. On my microsoft keyboard, all combinations work fine. Go figure.

    Clint on Jun 9, 2008 | Reply

  7. So it is not anything we can do ?? This sounds like it can’t be, there it should be some fix or something, I’m developing a game right now and when i press LEFT then UP then SPACEBAR it doesn’t catch SPACEBAR it works if i press RIGHT then UP then SPACEBAR, if you have a solution please e mail me, richcoto@hotmail.com

    Ricardo on Aug 11, 2008 | Reply

  8. I believe Tony is correct – this is a keyboard hardware issue.

    Also, perhaps the reason some people are noticing varying results is that your demo is being lenient when detecting simultaneous key presses.

    For example: up+left+ should not work, but it you quickly tap the keys you can get your demo to accept it. To really gauge whether it’s working, you must press the keys down in succession, slow and deliberately, and hold them down.

    To fix the demo, when it detects all three down, it should:
    - disable keydown event listeners (but not keyup listeners)
    - wait for a small timeout (~50ms)
    - then retest to see if the state of all three keys are still down
    - re-enable keydown listeners

    Jeff on Feb 27, 2009 | Reply

Post a Comment