views:

70

answers:

1

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 structure or should I look elsewhere?

+5  A: 

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.)

Rob Kennedy
But when I use GetKeyState it's hard to know where the Shift came from (from what keyboard). :( I'll look into GetAsyncKeyState I haven't used that one yet.
Dian
Sorry, I didn't mean to suggest that you should use those functions. I merely mentioned them as examples of what the OS already provides for *ordinary* (non-raw) keyboard input. You're doing all the input yourself, though, so you'll be keeping track of things on your own.
Rob Kennedy
Oh okay. Thanks for clarifying. I'll try to implement the flag thing.
Dian
It worked. Thank you! :D
Dian