Non-event KB handling

      GetAsyncKeyState(<someKey>); - takes the virtual key code & returns a WORD indicating if the key is pressed.

 

Example:

// macros must always be on a single line in pgm
// macro - return true if key is down
#define KEY_DOWN(vkCode) ((GetAsyncKeyState(vkCode) & 0x8000) ? 1 : 0)

// macro – return true if key is up
#define KEY_UP(vkCode) ((GetAsyncKeyState(vkCode) & 0x8000) ? 0 : 1)

 

To use in a pgm:

// In game loop
if (KEY_DOWN(VK_ESCAPE))
    // exit
else if (KEY_DOWN(VK_SPACE))
   // fire weapons
else if (KEY_DOWN(VK_ENTER))
   // raise shields

where:

Symbol

Value (hex)

Meaning

VK_BACK

08

Backspace key

VK_TAB

09

Tab key

VK_RETURN

0D

Enter key

VK_SHIFT

10

Shift key

VK_CONTROL

11

Ctrl key

VK_PAUSE

13

Pause key

VK_ESCAPE

1B

Esc key

VK_SPACE

20

Spacebar

VK_PRIOR

21

Page Up key

VK_NEXT

22

Page Down key

VK_END

23

End key

VK_HOME

24

Home key

VK_LEFT

25

Left-arrow keys

VK_UP

26

Up-arrow key

VK_RIGHT

27

Right-arrow key

VK_INSERT

2D

Insert key

VK_DELETE

2E

Delete key

VK_HELP

2F

Help key

VK_0 - VK_9

30 – 39

0 – 9 keys

VK_A – VK_Z

41 – 5A

A – Z keys

VK_F1 – VK_F12

70 – 7B

F1 – F12 keys