Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 308
Dian Avatar asked Aug 19 '10 02:08

Dian


2 Answers

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

like image 93
Rob Kennedy Avatar answered Oct 01 '22 05:10

Rob Kennedy


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
like image 29
jamil Avatar answered Oct 01 '22 05:10

jamil