Why after I press the directional arrow ON, the function GetKeyState continues to give me a value greater than 0?
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
for(int i = 0; i < 1000; ++i)
{
if(GetKeyState(VK_UP))
{
cout << "UP pressed" << endl;
}
else
cout << "UP not pressed" << endl;
Sleep(150);
}
return 0;
}
and also, GetKeyState() function, can be used for normal character keys like 'a' ~ 'Z'. (it's not case sensitive)
From the documentation:
Since you are not processing messages, you'll want to call
GetAsyncKeyState
instead.Test for the key being pressed like this:
GetKeyState doesn't return a "boolean-like". Take a look at the documentation :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx
It seems that you need to do :
0x8000 if the result is a short or -127/-128 if the result is a char. Check the "return value" section of the documentation to see what you want