XNA 数字锁定影响输入

发布于 2024-11-07 19:16:18 字数 231 浏览 1 评论 0原文

我有一个中断,在键盘按键上给我协调键。当数字锁打开时,按键会显示为 Numpad1、Numpad2 等。当数字锁关闭时,数字键盘键会变成 End、Left、Right、Up、PageLock...我不能让这种情况发生,因为我需要将这些键(左、右......)保留为实际的箭头键。我宁愿输入完全不受数字锁定的影响。然而,我似乎无法缓解这个问题,因为我直接从 XNA 获取输入。其他人可以确认 VS 2008 上的 XNA 3.1 中发生了这种情况吗?

I have an interrupt that on keyboard keypress gives me the coordinating key. When the number lock is ON, the keys come up as Numpad1, Numpad2, etc. When the number lock is OFF, the numpad keys turn into End, Left, Right, Up, PageLock... I cant have this happening because I need to keep those keys (Left, Right..) as the actual arrow keys. Id rather have the input not be affected by the number lock at all. However, I can't seem to mitigate this as I am getting the input from XNA directly. Can someone else confirm this is happening in XNA 3.1 on VS 2008?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝颜夕 2024-11-14 19:16:18

XNA 内部使用 win32 函数 GetKeyboardState来确定键盘状态。此功能无法区分数字键盘、方向键和插入组。

显然,您可以使用 来区分密钥WM_KEYDOWN 消息(及其朋友)。

我将保留在 XNA 应用程序中获取 win32 消息所需的互操作以及如何检查消息数据作为练习。

(我个人建议简单地修改您的控制方案。或者只是观察用户的数字锁定状态。一般来说,接管诸如数字锁定键之类的功能是一个坏主意!)

XNA internally uses the win32 function GetKeyboardState to determine the keyboard state. This function cannot differentiate between the number pad, the arrow keys, and the insert group.

Apparently you are able to differentiate between the keys by using the WM_KEYDOWN message (and its friends).

I'll leave the interop required to get win32 messages in an XNA application, and how to check the data for the message, as an exercise.

(Personally I would recommend simply modifying your control scheme. Or just observing the user's num-lock state. Generally speaking it is a bad idea to take over the functionality of something like the num-lock key!)

孤君无依 2024-11-14 19:16:18

您可以为游戏中的每个动作定义 2 个键。

例如,不使用 Keys.Left 向左移动,而是为其分配另一个键 (Numpad4)。

在输入检查代码中,您只需检查是否按下了这 2 个键中的任何一个:

例如:

if (IsKeyPressed(Keys.Numpad4) || IsKeyPressed(Keys.Left)
{
    // Do some action.
}

当然,您也可以创建一个接受 2 个键并在内部执行此操作的方法,而无需每次都编写代码。

You can define 2 keys for each action in your game.

For example, instead of Keys.Left for moving left, have another key allocated for it (Numpad4).

In your input checking code, you would simply check if any of these 2 keys are pressed:

For example:

if (IsKeyPressed(Keys.Numpad4) || IsKeyPressed(Keys.Left)
{
    // Do some action.
}

Off course you can also create a method that accepts 2 keys and performs this internally, without needing to write the code every time.

毁我热情 2024-11-14 19:16:18

我还没有验证这一点,但 Morpheus Development 的 Ryan Rubley 在这里发布了一个值得查看的解决方案:

http://xboxforums.create.msdn.com/forums/p/90944/545124.aspx#545124

这是一个完全有效的解决方案,可以使用数字键盘键,无论
numlock的状态,并且不打开numlock

由 Ryan Rubley 创建于 2011 年 9 月 5 日

I have not verified this yet, but Ryan Rubley of Morpheus Development has posted a solution here that is worth checking out:

http://xboxforums.create.msdn.com/forums/p/90944/545124.aspx#545124

Here is a fully working solution to use the numpad keys regardless of
numlock's status, and without turning on the numlock

Created by Ryan Rubley 9-5-2011

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文