#include <iostream>
#include <conio.h> // yes yes, bad for C++, it's a very small project though
#include <windows.h>
// The function that I'm talking about:
void WaitForEscKey()
{
std::cout << "Press 'esc' or 'ctrl+c' to exit ..." << std::endl;
bool finished = false;
while (!finished)
{
int key = _getch();
// 3 stands for CTRL-C and 27 for esc
if (key == 3 || key == 27)
{
std::cout << "Exiting ";
// generic
for (int i = 1; i <= 3; i++)
{
Sleep(100);
std::cout << ".";
}
finished = true;
}
}
exit(1); // Exit directly
}
int main()
{
// If I press 'esc' or 'ctrl+c' while the CPU 'sleeps', the function below executes ...
// The key stroke gets stored in memory.
Sleep(4000);
// Here, I need to ignore every key that i pressed before the function call
WaitForEscKey();
return EXIT_SUCCESS;
}
How do I ignore every pressed key until my function call? I have tried std::cin.ignore() but it does not work ...
This post has been edited by alekk: 22 January 2010 - 03:33 PM

New Topic/Question
Reply




MultiQuote






|