This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at
http://faq.perl.org .
--------------------------------------------------------------------
8.5: How do I read just one key without waiting for a return key?
Controlling input buffering is a remarkably system-dependent matter. On
many systems, you can just use the stty command as shown in "getc" in
perlfunc, but as you see, that's already getting you into portability
snags.
open(TTY, "+
system "stty cbreak /dev/tty 2>&1";
$key = getc(TTY); # perhaps this works
# OR ELSE
sysread(TTY, $key, 1); # probably this does
system "stty -cbreak /dev/tty 2>&1";