in reply to y/n input in a captive interface
I'm assuming, since you mentioned bash and tcsh that you're in Linux or Unix.
I've always used stty in conjunction with dd for this kind of thing. For example, the following should help you get there:
use strict; use warnings; $| = 1; print "Enter some characters below, <Escape> to quit\n"; chomp(my $stty = `stty -g`); # Save state system("stty -icrnl -icanon -echo min 0 time 0"); # Raw mode while (1) { my $k = `dd bs=1 count=1 <&0 2>/dev/null`; next unless $k; # No character entered last if (27 == ord $k); # Finish if char is <Escape> printf "Ascii = %d\n", ord($k); } system("stty $stty"); # Restore cooked mode (thanks, sgt!) print "\nDone!\n";
It reads characters one at a time, displaying their ascii value, until you type an Escape. Of course, you could easily modify it to read only a single character, or as many as you need.
Good luck!
Update: Good catch sgt. I've added the line system("stty $stty"); to restore "cooked" mode.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: y/n input in a captive interface
by sgt (Deacon) on Feb 08, 2007 at 00:19 UTC | |
|
Re^2: y/n input in a captive interface
by apotheon (Deacon) on Feb 08, 2007 at 05:08 UTC |