Hey, Im making a program in C++ that detects what the user types before pressing enter. So it uses GetAsyncKeyState in the following way:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main() {
SetCurrentDirectory("C:\\");
ofstream log;
char loop;
string input;
loop = 'a';
while(loop = 'a') {
if(GetAsyncKeyState(VK_0x41)) {
cout << "a" << endl;
input+="a";
Sleep(1000);
}
//Rest of GetAsyncKeyState alphabet and some other commands
if(input == "hello") {
cout << "You successfully entered hello" << endl;
Sleep(1000);
getch();
return 0;
}
So its a basic program and it would have the rest of the GetAsyncKeyState alphabet and a couple other buttons, and it works fine. But if I don't add the Sleep(1000); to sleep for 1 sec between getting sync key states, it infiniately prints (outputs) the letter I entered. So if I say Sleep(80) it prints the letter I entered 2 times. Sleep(60), 4 times etc.
So its annoying cause it takes forever to type and misses a couple keys I press with the Sleep functions in between. But without them, it will keep printing out the sync key state key. It won't stop.
Is there any way or any other command I can use that does the same thing, but keeps up with printing keys as I type, and doesn't keep on printing out keys infinately at a very high speed, until I close the program? Even with the cout << "You sucessfully entered hello!" <<endl; command, it keeps printing out that line over and over....
Please help!
Thanks in advance,
Aidan.