Basically If the user does not enter a string or character or press any keys after a certain length of time, program will goto or ask again.. or do whatever..
Problem: Not allowing the user to enter input.. Note accepting user input..
#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;
string pword;
int main()
{
printf("You have 5 seconds to Enter the Password: ");
static HANDLE stdinHandle;
// Get the IO handles
// getc(stdin); //If I take out the // from infront of getc(stdin); user can type but it doesnt accept it..
stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
while (1)
{
DWORD rc = WaitForSingleObject(stdinHandle, 5000);
if( rc == WAIT_TIMEOUT )
{
//printf("Timeout...");
return 0;
}
else if( rc == WAIT_OBJECT_0 )
{
INPUT_RECORD r[512];
DWORD read;
ReadConsoleInput(stdinHandle, r, 512, &read);
}
else if( rc == WAIT_FAILED )
{
printf("Error:%d.", GetLastError());
}
else
{
cin>>pword;
if(pword == "correct")
{
cout<<"Nicely done!";
}
}
}
return 0;
}