GetAsyncKeyState(VK_) Trouble

How do you get it to tell you when you hit enter?

This doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
if(GetAsyncKeyState(VK_ENTER)){
    cout << "you hit ENTER";

}else{
cout << "you failed";
}
}
That doesn't just not work, it doesn't compile. (Hint: there's no such thing as VK_ENTER. Use VK_RETURN.)

Remember, GetAsyncKeyState() gets the state of the keys at the time you call the function.

(Chances are you will be unable to release the Enter key fast enough for the program to print "you failed".)

Hope this helps.
Thanks.
Also note that you are only interested in bit 15 of the output:

1
2
3
if(GetAsyncKeyState(VK_RETURN))  // <- WRONG

if(GetAsyncKeyState(VK_RETURN) & 0x8000) // <- RIGHT 
Topic archived. No new replies allowed.