Created
December 18, 2022 10:54
-
-
Save lyf-is-coding/08ff4a95fc6dc9ecb6084e0e442cc16f to your computer and use it in GitHub Desktop.
Windows C++ Check for key input using GetAsyncKeyState
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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