XNA 数字锁定影响输入
我有一个中断,在键盘按键上给我协调键。当数字锁打开时,按键会显示为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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!)
您可以为游戏中的每个动作定义 2 个键。
例如,不使用 Keys.Left 向左移动,而是为其分配另一个键 (Numpad4)。
在输入检查代码中,您只需检查是否按下了这 2 个键中的任何一个:
例如:
当然,您也可以创建一个接受 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:
Off course you can also create a method that accepts 2 keys and performs this internally, without needing to write the code every time.
我还没有验证这一点,但 Morpheus Development 的 Ryan Rubley 在这里发布了一个值得查看的解决方案:
http://xboxforums.create.msdn.com/forums/p/90944/545124.aspx#545124
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