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.

Revisions

  1. lyf-is-coding created this gist Dec 18, 2022.
    25 changes: 25 additions & 0 deletions Check_for_key_input_using_GetAsyncKeyState.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #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";
    }
    }
    }