Hello all, I am trying to make a basic program in c++.
It uses "GetAsyncKeyState();" to outout the keys I press.
It works with things like "GetAsyncKeyState(VK_F8);", but I cant figure out what to use to output numbers.
I've tried "GetAsyncKeyState(VK_1)" and I just get an error messaeg in the compiler.
HELP??????
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
For the numpad numbers, you can use VK_NUMPAD0, VK_NUMPAD1, etc... For the main keyboard numbers, there are no defines, because you can just use the ASCII character, '0', '1', '2' etc... Same thing applies to letters, you just use the capital ASCII character, 'A', 'B', 'C' etc...
Here's a list of all virtual key codes.
http://delphi.about.com/od/objectpascalide/l/blvkc...
You'll notice that only the hexadecimal value is listed for number and letter keys. That value is equal to the ASCII code of the character that key represents.
GetAsyncKeyState does not test for characters, it tests keystates. It doesn't know the difference between 2 and @, because they are on the same key. You need to test for both the key '2' and shift at the same time: (((GetAsyncKeyState('2') & 0x8000) && (GetAsyncKeyState(VK_SHIFT) & 0x8000)) == true)