Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lyf-is-coding/08ff4a95fc6dc9ecb6084e0e442cc16f to your computer and use it in GitHub Desktop.
Save lyf-is-coding/08ff4a95fc6dc9ecb6084e0e442cc16f to your computer and use it in GitHub Desktop.
Windows C++ Check for key input using GetAsyncKeyState
#include <Windows.h>
int main()
{
const int keyW = 0x57;
while(true)
{
if (GetAsyncKeyState( keyW ) & 0x8000)
{
std::cout << "key is held down\n";
}
else if (GetAsyncKeyState( keyW ) & 0x0001)
{
// only excute 1 time after key is pressed
std::cout << "key is pressed\n";
}
else
{
std::cout << "no key interaction\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment