gpt4 book ai didi

c# - XNA Keyboard.GetState() 不返回所有按下的键

转载 作者:行者123 更新时间:2023-12-03 04:09:51 26 4
gpt4 key购买 nike

我正在学习 XNA(v. 4.0),并且正在努力使用键盘上的箭头键移动 Sprite ,并在按住空格时使角色冲刺。

下面是我的代码,用于确定按下了哪些键:

currentKBState = Keyboard.GetState();

bool right = currentKBState.IsKeyDown(Keys.Right);
bool left = currentKBState.IsKeyDown(Keys.Left);
bool up = currentKBState.IsKeyDown(Keys.Up);
bool down = currentKBState.IsKeyDown(Keys.Down);
bool space = currentKBState.IsKeyDown(Keys.Space);

System.Diagnostics.Debug.WriteLine(String.Format("{0} {1} {2} {3} {4}", right, left, up, down, space));

问题是我无法同时按下所有 5 个按钮。有时只有两个人会注册。例如,如果我按住向上、向下和向左,则无论我按住这三个键多长时间,它都只表示向上和向下是正确的。我希望能够处理无论按下什么组合。为什么它不记录所有被按下的按钮?我需要采取不同的方式吗?

最佳答案

这不是代码问题。这是键盘硬件的限制。

廉价键盘可以可靠地检测两个并发按键,但在三个按键的某些组合下可能会失败。

参见Rollover (key)

Modern keyboards detect ghosting, and instead of registering a fourth key, they will ignore the third key, which is known as jamming. Which keys jam when pressed together differs between brands and models of keyboards. Due to the keyboard matrix most consumer keyboards use, jamming and ghosting often occur when three out of four keys in a square block on the matrix are pressed, such as QASW or JKUI.

关于c# - XNA Keyboard.GetState() 不返回所有按下的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22237518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com