I want to ignore all key presses while sleep function is going on.
example:
void main()
{
char option,option2;
int timer = 1500;
do
{
bool finished = true;
cout << "Press an arrow key" << endl;
option = _getch();
if(option == char(224))
{
option2 = _getch();
switch(option2)
{
case 'M' : cout << "Right key was pressed" << endl;break;
case 'P' : cout << "Down key was pressed" << endl; break;
case 'K' : cout << "Left key was pressed" << endl;break;
case 'H' : cout << "Up key was pressed" << endl;break;
};
}
if(option == '\r')
{
cout << "Return key was pressed." << endl;
}
while(finished)
{
Sleep(timer);
/*I want to ignore all key presses during the loop or until Sleep() is over.*/
}
cout << endl;
}while(!(option == 'q' || option == 'Q'));
There is a function called FlushConsoleInputBuffer() that will do what you want if you call it immediately after the Sleep function. Hope this helps.