09-16-06 06:43 PM
On Thu, 14 Sep 2006 03:17:24 +0800, "Key9" <publicaccept@163.com> wrote:
>Hi all
>
>I am trying to write some console app
>but I found that ncurses/SLang is too big for me,
>
>also it still need to wrote code to process key combination something like
>CTRL+ALT+P
>
>What I need is a directly responsed getch();
>and a defined keymap.
>
>Is there any sample or issue of that?
>
>
> thank you very much
> your key9
Check out Perl's Term::ReadKey.
Search Google and groups.google for more
complex examples.
#!/usr/bin/perl
use warnings;
use strict;
use Term::ReadKey;
#passing ReadKey() an argument of -1 to indicate not to block:
ReadMode('cbreak');
while(1){
my $char;
if (defined ($char = ReadKey(0)) ) {
print "$char->", ord($char),"\n"; # input was waiting and it
was $char
if(ord($char) == 144){ print "Got a Ctrl-Alt-p\n" }
} else {
# no input was waiting
# do whatever
}
}
ReadMode('normal'); # restore normal tty settings
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[ Post a follow-up to this message ]
|