August 1998
Intermediate to advanced
800 pages
39h 20m
English
You want to know whether keyboard input is waiting without actually reading it.
Use the CPAN module Term::ReadKey, and try to read a key in
non-blocking mode by passing it an argument of -1:
use Term::ReadKey;
ReadMode ('cbreak');
if (defined ($char = ReadKey(-1)) ) {
# input was waiting and it was $char
} else {
# no input was waiting
}
ReadMode ('normal'); # restore normal tty settingsThe -1 parameter to ReadKey
indicates a non-blocking read of a character. If no character is
available, ReadKey returns
undef.
The documentation for the Term::ReadKey module from CPAN; Section 15.6