enoch has asked for the wisdom of the Perl Monks concerning the following question:
which, obviously, did not work. I needed something that would not wait for a return. So, I started searching around for some non-blocking I/O calls; and I found this reply in this thread. So, I got the "any key phenomenon" to work with this code:my $key; while(undef($key)) { $key = <STDIN>; }
So, I had that working wonderfully. However, my terminal was going crazy. It would ignore CTRL-C and the like, it would interpret a return as ^M, etc. So, I decided to change the I/O gathering back to normal using the following code that directly follows the above while loop:my $key; my $term = new POSIX::Termios; $term->setlflag(~ICANON); # turn canonical mode off $term->setcc(VMIN,1); # read 1 char min $term->setcc(VTIME,0); # no timeout $term->setattr(0,TCSANOW); # apply it to STDIN while( read(STDIN,$key,1) ) { last if(defined($key)); }
But, alas, that does nothing. How do you reset STDIN? And, just in case, if anyone else has a better idea about implementing "press any key," I am all ears.$term->setlflag(ICANON); # set back to canonical mode $term->setattr(0,TCSANOW); # apply it to STDIN undef($term); # cleaning up
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where Is The 'AnyKey'?
by yakko (Friar) on Mar 06, 2001 at 02:10 UTC | |
by enoch (Chaplain) on Mar 06, 2001 at 02:33 UTC | |
|
Re: Where Is The 'AnyKey'?
by strredwolf (Chaplain) on Mar 06, 2001 at 03:12 UTC |