且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测按键

更新时间:2022-04-28 08:52:23

KeyboardState类具有PressedKeys只读属性,其中包含按下键的IList<Key>.

KeyboardState class has a PressedKeys read-only property which contains an IList<Key> of pressed keys.

您可以检查此列表是否为空,以了解没有按下任何键(kbd.PressedKeys.Count == 0).

You can check if this list is empty to know that nothing is pressed (kbd.PressedKeys.Count == 0).

如果要响应键盘事件并避免轮询模式(对按键是否进行显式检查),则应查看SlimDX.RawInput命名空间并使用按键事件处理,类似于WinForms.

If you want to respond to keyboard events and avoid the polling mode (explicit checks for keypresses) you should look to SlimDX.RawInput namespace and use the key press event handling, similar to WinForms.