Search code examples
c++windowsraw-input

RAWKEYBOARD Flags, checking which flags are on, also SHIFT, CTRL and ALT


So I am working with RAWINPUT and I am trying to figure out how to check this:

data.keyboard.Flags

to see what flags are on, I want to be able to check for things like key up and key down as well as left and right keys.

Do you need to do something like this:

if(data.keyboard.Flags == (RI_KEY_MAKE|RI_KEY_E0))

and

if(data.keyboard.Flags == (RI_KEY_BREAK|RI_KEY_E0)) 

I know for the SHIFT key I should check the makecode left being: 0x2a right being: 0x36

what about the CTRL and ALT keys


Solution

  • You'll need to know the raw scan codes for the keys. The core reference for them is this Word document. A bit hard to wrestle through, the scan code table on page 16 is the most useful resource.

    Do note how you have to be careful with the E0 flag. It is used for keys that were added in later keyboard designs. The original IBM PC keyboard always had two shift keys so they are sent with dedicated scan codes without E0. But Right-Ctrl and Right-Alt were added later, their scan codes are respectively E0 1D and E0 38, the left ones are 1D and 38 without the E0 flag.