I was wondering if there was a way to ignore getch() after an amount of time has passed.
Like, if i wanted the user to press a key within 5 seconds of me telling them to, or else the program closes, or something like that. How would I do that, or is there something other than getch() that has to bee used?
It seems you two have different opinions :P. I checked out SFML, and ill probably get into that. I'm just using console until i learn some more in a class im taking soon.
@Superdude: Because threads and console I/O are generally messy and hard to get right (just like threading in general) except moreso since console I/O is not meant to be used with threads.
One f the more easier alternatives for beginners would be to use _kbhit() from the (severely depricated) conio.h header file. it will return true if a key was pressed (or if there is a character key code in the buffer), and false otherwise.
If you are up to it, I would suggest following LB's approach.
Example:
Psuedo Code:
1 2 3 4 5 6 7 8 9 10
char ch;
while(time != time_up)
{
//update the time here... etc...
if(kbhit())
{
ch = getch();
}
}
//user pressed nothing, return nothing, or somthing