Store the value of any key the user presses

Is there a easier way of detecting any button the user presses and storing it in a variable then just making a lot of if statements with GetAsyncKeyState?
Last edited on
Almost always a long chain of if-statements is a bad idea. Switches are similarly bad in many cases -- but at least those usually assemble to a computed goto, and so there's a performance consideration there that makes them more acceptable in some cases.

From here
https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
I found out that there are precisely 256 virtual keycodes, and that's a reasonably small number.

But instead of updating an entire array with 256 calls to a library function in a loop, it looks like you can use GetKeyboardState instead.
1
2
3
BYTE key_states[0x100]; 
GetKeyboardState(key_states);
... use key_states[VK_WHATEVER] to do whatever. 
Topic archived. No new replies allowed.