BEGIN { use POSIX qw(:termios_h); use sigtrap qw( INT ); $Signal = 0; our $config = qx/stty -g/; my ($term, $oterm, $echo, $noecho, $fd_stdin, $iterm, $raw, $allraw); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON ; $noecho = $oterm & ~$echo; $iterm = $term->getiflag(); $raw = ICRNL; $allraw = $iterm & ~$raw; $SIG{INT} = \&TST_INT; sub TST_INT { our $Signal++; return; } sub cbreak { my $max = shift; $term->setlflag($noecho); $term->setiflag($allraw); $term->setcc(VMIN, 0); $term->setcc(VTIME, $max); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setiflag($iterm); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub getkey { my $tm = shift; $key = ""; $chr = ""; cbreak($tm); sysread(STDIN, $chr, 1); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); GETLOOP: #$# Need to test for multiple character Carr Return if ( $er == 22 ) { return(""); } if ( $chr ne "" ) { $key .= $chr; if ( ( length($key) == 2 )&&( ord($key) < 32 ) ) { if ( substr($key,0,1) eq substr($key,1,1) ) { chop($key); } } if ( ( length($key) > 1 )&&( exists $CRTinput{$key} ) ) { if ( $Debug >= 3 ) { PEMSG(3," GETKEY1:\t|$key|"); } return $key; } if ( $chr ne $TERMCR ) { sysread(STDIN, $chr, 1); goto GETLOOP; } } if ( ( $Debug >= 3 )&&( length($key) > 1 ) ) { PEMSG(3," GETKEY2:\t|$key|"); } # cooked(); return $key; } sub clrkey { my $char = ""; $term->setlflag($noecho); $term->setiflag($allraw); $term->setcc(VMIN, 0); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); sysread(STDIN, $char, 64); } } END { cooked(); qx/stty $config/; print "\n\n"; $|=1; }