Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user input within 10 seconds

Status
Not open for further replies.

raydona

Programmer
May 12, 2005
27
0
0
GB
I am writing a small games program, console not Windows application, that requires the user to enter an integer within 10 seconds. If none is entered the system takes a different course of action. How can I code this, that is, say:
int x;
cin >> x; //within 10 seconds

I would be very grateful for all help.
 
If you are using DOS, you could try something like
Code:
time_t now, expire;
expire = time(NULL) + 10;
now = time(NULL);
while (!_kbhit() && now < expire)
{
   now = time(NULL);
}
if (kbhit())
   cin >> x;
If you're on Windows, theh try having a look at SIGALRM. It may or may not work.

You could also try overlapped input (look up high-level console functions) and set some kind of timeout accordingly.



[/CODE]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top