- Joined
- Nov 23, 2006
- Sythe Gold
- 1,609
- Messages
- 7,145
- Location
- Canada
- Discord Unique ID
- 178533992981594112
Hello, here's my code:
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.
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.

























