What is the code for the AsyncKeyState function?
-
In the Win32 API (or atleast I think it's in the Win32 API), the AsyncKeyState function can be used to see if a keyboard button is pressed. Does anyone know the code for the buttons on the keyboard? I arleady know that the arrow keys are VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT, and the "Enter" button is VK_RETURN. Thanks!
-
In the Win32 API (or atleast I think it's in the Win32 API), the AsyncKeyState function can be used to see if a keyboard button is pressed. Does anyone know the code for the buttons on the keyboard? I arleady know that the arrow keys are VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT, and the "Enter" button is VK_RETURN. Thanks!
Constants like these are defined in the headers that are installed with VC++. If you find, for example,
VK_UP
then you can see all the others. They are defined in winuser.h and documented at http://msdn.microsoft.com/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp[^]. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
Constants like these are defined in the headers that are installed with VC++. If you find, for example,
VK_UP
then you can see all the others. They are defined in winuser.h and documented at http://msdn.microsoft.com/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp[^]. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]I see. But what about the letter keys. All the list says is, for example: (48) H Key; (4D) M Key How would you use that in code when trying to do something like this: if (GetAsyncKeyState(VK_LEFT) < 0) { //result of key press here } Instead of using VK_LEFT, how would I use the letter "M" or the letter "H"? Thanks again!
-
I see. But what about the letter keys. All the list says is, for example: (48) H Key; (4D) M Key How would you use that in code when trying to do something like this: if (GetAsyncKeyState(VK_LEFT) < 0) { //result of key press here } Instead of using VK_LEFT, how would I use the letter "M" or the letter "H"? Thanks again!
(48) H is an example of the value of the constant. All the
VK_*
are is constants defined for a particular value. I suppose Microsoft didn't think it was necessary to defineVK
constants for printable ASCII characters, especially since the values are the same as the ASCII character code. So, the key constant for "A" is 0x41 (65), as well as the ASCII value. This makes it easy to translate key codes to printable ASCII characters. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]