开发者

How do I know if the shift is pressed using RawInput?

I'm using RawInput to deal with keystrokes. I'm finding it hard to determine if the shift is pressed together with a key.

From the RawInputStructure -> RawKeyboard, I can retrieve the key being pressed but I'm not sure how to go about things if the keys were pressed at the same time.

RI.Data.keyboard.VKey (gets the keycode)

I'm trying to separate the Shift for each user/keyboard because at the moment when one user/keyboard shifts all of them do, same with Capslock. Simultaneous typing gets really messy.

How can I know if the shift is pressed together with another key? Am I looking for it in the right st开发者_如何学Goructure or should I look elsewhere?


There's no such thing as two keys being "pressed at the same time." One goes down, and then the other. You should get notified of each one separately. When the shift key is pressed or released, set or clear a flag in your program to remember its current state.

That's in fact what the OS already does for ordinary keyboard input. It keeps a key-state map and updates it with each keyboard message. Use GetKeyState to check a key's state as of the most recent message to be processed, or use GetAsyncKeyState to check the key's state at the moment you call the function. (The two might be different if the keyboard state has changed but you haven't processed those keyboard messages yet, such as if the user is typing faster than your program can handle.)


You can try this method:

  1. when shift key down in raw input, save in memory for that device have shift status true
  2. when character key down, check the shift status as you record in point 1
  3. if shift still down, so the char you press have shift key altogether too
  4. after shift key up, reset your memory of shift status for that device to false again
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜