4

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?

4
  • possible duplicate of javascript multiple keys pressed at once Commented Aug 9, 2013 at 20:55
  • I believe the problem is not so much a JavaScript problem as it is a hardware problem. w3schools.invisionzone.com/index.php?showtopic=45663 Commented Aug 9, 2013 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. Commented Jan 26, 2020 at 19:13
  • Have you found any workaround? I hit same issue :/ Commented Mar 25, 2023 at 19:39

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.