GetAsyncKeyState not working right with letters

In the virtual key codes table on the Microsoft website, 0x41 is value for A, and 0x44 is the value for D. However, this is just printing (0, 0) all the time.

cout << GetAsyncKeyState(0x41) << ", " << GetAsyncKeyState(0x44) << endl;

Also, after doing some research I found out that 0x20 can be used to SendInput the key A in a video game that I play, and 0x1E does the same with D (but not working with GetAsyncKeyState). SendInput with 0x41 and 0x44 are only working in things that I can type in and not things that are used to perform a different action.

Here are some of the things I tried while researching the problem that did not work including the code above:

cout << GetAsyncKeyState('A') << ", " << GetAsyncKeyState('D') << endl;

cout << GetAsyncKeyState(0x20) << ", " << GetAsyncKeyState(0x1E) << endl;

Hope I made that clear enough. Please help.
Last edited on
Here is your problem:
MSDN wrote:
Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.

You have to make sure the letters are being pressed. Try holding A before running your program and see if the results change. I don't know much about any of the windows functions, so that might not even solve it.
The function is in a while loop so it is constantly being called. I know it works for all the Virtual Keys with a name for them like 'VK_LSHIFT'. But the letters will not work. I'm pretty sure the solution to this problem is that either I need to use a different value for the letters, or I need to find another library to use. In the case that I need to download a new header and lib file, I might need help installing them on VB 2012.
Again, I don't know much about them, but reading the descriptions on MSDN, it seems like you want GetKeyState instead:

I didn't read anything about Async being able to read keyboard values.
Thanks, GetKeyState does work.
Topic archived. No new replies allowed.