in reply to how to check for keyboard input
use strict; use warnings; use Term::ReadKey; my $done; while ( 1 ) { sleep 1; ReadMode( 'cbreak' ); if ( defined ( my $key = ReadKey( -1 ) ) ) { # input waiting; it's in $key $done = $key eq 'q'; } ReadMode( 'normal' ); exit if $done; # do stuff... }
Update: Thanks to Tanktalus for pointing out the exit bug. Also thanks to bobf for pointing out typo in comment. Both fixed.
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to check for keyboard input
by Tanktalus (Canon) on Jul 21, 2005 at 04:17 UTC | |
by chb (Deacon) on Jul 21, 2005 at 08:07 UTC | |
by benizi (Hermit) on Jul 21, 2005 at 17:17 UTC |