use POSIX qw(:termios_h);
$fd_stdin = fileno(STDIN);
$term = POSIX::Termios->new();
$term->getattr($fd_stdin);
$oterm = $term->getlflag(); |
$echo = ECHO | ECHOK | ICANON;
$noecho = $oterm & ~$echo; |
sub cbreak {
$term->setlflag($noecho);
$term->setcc(VTIME, 1);
$term->setattr($fd_stdin, TCSANOW);
} |
sub cooked {
$term->setlflag($oterm);
$term->setcc(VTIME, 0);
$term->setattr($fd_stdin, TCSANOW);
} |
sub readkey {
my $key = '';
cbreak();
sysread(STDIN, $key, 1);
cooked();
return $key;
} |
| Forward to Compiled vs interpreted
Back to Input from the keyboard Up to Stages of a Perl Programmer section index Up to YAPC 2000 course index |
YAPC 2000: Stages of a Perl Programmer - 8
Copyright © 2000, Nathan Torkington
|