jmClifford has asked for the wisdom of the Perl Monks concerning the following question:
Hi. I am wanting to do a non blocking type of read of the console input. I am trying to established a timed loop that performs as such that. The input response is only to indicate the operators wish to exit (the looping).
I am using Win 10 and Perl version 5.32.
From the web I get the following program as a possible approach;
use strict; use warnings; use Time::HiRes qw(usleep); print "start\n"; usleep(2000000); print "finish\n"; use Term::ReadKey; ReadMode 4; # Turn off controls keys 4 or "raw" my $key; while (not defined ($key = ReadKey(-1))) { # No key yet print "."; usleep(2000000); } print "Get key $key\n"; ReadMode 0; # Reset tty mode before exiting
The console output is;
start finish GetConsoleMode failed, LastError=|6| at C:/Strawberry/perl/vendor/lib/ +Term/ReadKey.pm line xxx.
The execution failure above is on ReadMode 4.
Are there any thoughts on why this failure occurs ?? I am surprised at the difficulty of achieving a non-blocking IO request and the lack of setting of say, a timeout of 0.
Regards JC.....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Non blocking read from the console
by SankoR (Prior) on Oct 18, 2024 at 15:53 UTC | |
by jmClifford (Beadle) on Oct 19, 2024 at 01:13 UTC | |
by SankoR (Prior) on Oct 19, 2024 at 01:31 UTC | |
by jmClifford (Beadle) on Oct 20, 2024 at 04:34 UTC | |
|
Re: Non blocking read from the console
by hippo (Archbishop) on Oct 18, 2024 at 15:11 UTC | |
|
Re: Non blocking read from the console
by Anonymous Monk on Oct 18, 2024 at 18:37 UTC | |
by soonix (Chancellor) on Oct 18, 2024 at 20:39 UTC |