简体   繁体   中英

JavaScript KeyDown event not triggered when multiple keys are held down

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?

这是USB键盘的限制,而不是您的代码!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM