Hello, here's my code:
Code:
#include <iostream>
#include <Windows.h>
using namespace std;
int main(){
short key;
do {
key = GetAsyncKeyState(VK_UP);
if (key < 0)
cout << "Up key pressed" << endl;
} while (1);
return 0;
}
It works for its purpose (detecting whether the arrow key is pressed), but when it IS pressed, the output outputs like 50 lines. I just want it to output once. I don't like using sleep, because sleep pauses the current thread. That means that if I use sleep(100); then during that 100ms I cannot push the up arrow key again.
Thanks for any help!
EDIT: Just ended up going with getch() from conio.h, it gives me the results I was looking for.