in reply to Timed wait for input
A version that does the timeout as well:
use warnings; use strict; use Term::ReadKey; my $key; my $start = time (); local $| = 1; print "Press a key: "; while (not defined ($key = ReadKey(-1))) { last if time () - $start > 10; } print defined $key ? "\nGot key $key\n" : " No key after 10 seconds";
|
|---|