문제

I am currently checking the keyboard state in my program:

SlimDX.DirectInput.KeyboardState keyboardState = keyboard.GetCurrentState();

And detecting key presses like this:

 if(keyboardState.IsPressed(SlimDX.DirectInput.Key.Q))...

I can't figure out how to detect ANY key press, rather than specific keys. I can't put my finger on it after trawling through the SlimDX API documentation. I'm probably missing something really simple no doubt.

도움이 되었습니까?

해결책

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

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top