为什么 CraftyJS/Chrome 限制并发按键事件的数量?

Why does CraftyJS/Chrome limit the number of concurrent key press events?

我正在尝试使用 CraftyJS 开发游戏。我正在使用

我注意到键盘事件的处理方式有些奇怪。 我猜这在很大程度上与 Chrome 甚至可能有关 我的物理键盘,而 Crafty 只与我相关 使用它 API.

首先,这是我的 SSCCE。此代码在按下时向 keys 数组添加一个键,在释放时将其删除,并每秒注销该数组。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>keyTest</title>
    <script src="../crafty.js"></script>
    <script>
        window.onload = function(){
            Crafty.init(window.innerWidth, window.innerHeight, document.getElementById('game'));
            var keys = [];

            var keyDown = function(e){
                console.log("KeyDown " + e.key);
                keys.push(e.key);
            };

            var keyUp = function(e){
                console.log("KeyUp " + e.key);
                keys.splice(keys.indexOf(e.key), 1);
            };

            Crafty.e("Keyboard").bind("KeyUp", keyUp).bind("KeyDown", keyDown);
            Crafty.e("Delay").delay(function(){console.log(keys)}, 1000, -1);
        };

    </script>
</head>
<body>
<div id="game"></div>
</body>
</html>

我注意到一些奇怪的行为:

这到底是怎么回事?我的猜测是我的手指和我的 JS 之间有人试图巧妙地纠正错误的按键(拼写错误),但我不知道是谁,我也不知道是什么规则来管理这个。

编辑:我怀疑是我的键盘本身(或 OS)未能发送这些键盘事件。但我仍在寻找确认这一点的好方法。

正如@David 发现的那样,这个问题被称为 keyboard ghosting

"Ghosting" is the problem that some keyboard keys don't work when multiple keys are pressed simultaneously. The key presses that don't show up on the computer or seem to have disappeared are said to have been "ghosted". On most keyboards, even some that are explicitly marketed as "Anti-Ghosting," this happens with many three key combinations. Imagine playing your favorite video game and not being able to, say, run diagonally and fire your weapon at the same time (say pressing a, w, and g simultaneously). This is a result of the internal design of most existing keyboards...

由于并非每个消费者都有游戏键盘(尤其不会遇到此问题),我想您唯一能做的就是围绕不需要同时按下三个或更多键来设计您的游戏.