2

I am experiencing a strange problem with JavaScript. I am working on a HTML5 canvas game that uses keyboard input. The two player mode of the game involves up to 6 keys on the keyboard being pressed and held down.

It seems like the "keyDown" event stops being called after I hold 4 or 5 keys down on the keyboard.

The code I am using is below:

window.onkeydown = function (event) {
    console.log(event.keyCode);
    input.onKeyDown(event.keyCode);
};

The console should log a key code for each key I press down. However, it only seems to report the keycode for the first 4 or 5 I hold down. This is causing the controls for the two player version of my game to not work when both players press too many keys.

Is this a bug, a limitation of JavaScript/HTML5, or am I doing something wrong?

  • possible duplicate of [javascript multiple keys pressed at once](http://stackoverflow.com/questions/5203407/javascript-multiple-keys-pressed-at-once) – putvande Aug 09 '13 at 20:55
  • I believe the problem is not so much a JavaScript problem as it is a hardware problem. http://w3schools.invisionzone.com/index.php?showtopic=45663 – Steven Lambert Aug 09 '13 at 21:47
  • I found out that, if you keep down 3 arrow keys, if you press a fourth one, it is ignored. Indeed suspicious. – Ambroise Rabier Jan 26 '20 at 19:13

1 Answers1

1

This is a limitation of the USB keyboard not of your code!

jknight
  • 141
  • 1
  • 7