in reply to Disabling keyboard input
You need to clear the input buffer before reading the next response.
Maybe this module does already cover all your requirements? IO::Prompter or Term:UI
Update: The following method clears the input buffer (at least on Unix):
use Term::ReadKey; sub flush_stdin { ReadMode 4; ReadLine(-1); ReadMode 0; } sleep 5; # type 'something' flush_stdin(); $|=1; print "---> "; chomp (my $answ = <STDIN>); print "answ: ($answ)\n"; # w/o 'something'
Update: Cannot test it under Windows, but maybe Win32::Console works (see Flush() method)?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Disabling keyboard input
by hegotf (Novice) on Aug 09, 2011 at 18:55 UTC | |
|
Re^2: Disabling keyboard input
by hegotf (Novice) on Aug 09, 2011 at 16:36 UTC |