简体   繁体   English

按住多个键时未触发JavaScript KeyDown事件

[英]JavaScript KeyDown event not triggered when multiple keys are held down

I am experiencing a strange problem with JavaScript. 我在JavaScript中遇到了一个奇怪的问题。 I am working on a HTML5 canvas game that uses keyboard input. 我正在使用键盘输入进行HTML5画布游戏。 The two player mode of the game involves up to 6 keys on the keyboard being pressed and held down. 游戏的两人游戏模式涉及最多按住键盘上的6个键。

It seems like the "keyDown" event stops being called after I hold 4 or 5 keys down on the keyboard. 按下键盘上的4或5个键后,似乎似乎不再调用“ keyDown”事件。

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. 但是,似乎只报告了我按住的前4或5个键码。 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? 这是错误,是JavaScript / HTML5的限制,还是我做错了什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript:限制按下按键事件监听器在按下时可以多快调用一次函数 - Javascript: Limit how quickly a keydown event listener can call a function when held down jQuery使用keydown / keyup / keypress事件仅触发一次,而不是按住键时触发多次 - jQuery using keydown/keyup/keypress event to fire only one time instead of multiple times when key held down 当按住箭头键时,如何在Firefox中获得自动重复的keydown事件? - How can I get auto-repeated keydown events in Firefox when arrow keys are held down? Javascript Keydown事件被触发两次 - Javascript Keydown event is triggered twice HTML Canvas:按住键时控制键按下注册表 - HTML Canvas: Controlling keydown registry when key is held down 如果触发了 keydown 事件,则防止模态关闭 - Prevent modal from closing down if there is a keydown event that has been triggered 按住鼠标时 JavaScript 重复动作 - JavaScript repeat action when mouse held down 如何在不捕获keydown事件的情况下查看修改键是否被按下? - How to see if a modifier key is being held down without catching the keydown event? 当事件由“ESC”键触发时,表单未在keydown事件中提交 - Form not submited on keydown event when event is triggered by 'ESC' key 控制多个按键时出现奇怪的情况 - Strange occurrences with controlling multiple keys being held down
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM