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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32: Can a read from STDIN be timed out?

Status
Not open for further replies.

GDameron

Programmer
Aug 8, 2003
39
US
I saw (and appreciated) the solutions others have posted for this problem under Unix -- is there a Win32 solution?
 
Here's a solution:
Code:
use Term::ReadKey;
ReadMode 4; # Turn off controls keys
my $TimeOut = 5;
my ($Key, $i);
print "Waiting $TimeOut seconds for input: ";
for ($i=0; $i<$TimeOut; $i++) {
    last if (defined($Key = ReadKey(-1)));
    sleep(1);
}
if (defined($Key)) {
    print &quot;Got key $Key \n&quot;;
} else {
    print &quot;\nTimed out on STDIN \n&quot;;
}
ReadMode 0; # Reset tty mode before exiting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top