2
votes

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?

1
I believe the problem is not so much a JavaScript problem as it is a hardware problem. w3schools.invisionzone.com/index.php?showtopic=45663 - Steven Lambert
I found out that, if you keep down 3 arrow keys, if you press a fourth one, it is ignored. Indeed suspicious. - Ambroise Rabier

1 Answers

1
votes

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