For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > is there any small lib thar can process key combination on terminal









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author is there any small lib thar can process key combination on terminal
Key9

2006-09-13, 7:02 pm

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


key9

2006-09-13, 7:02 pm

PS also because <alt><shift>... not send the signal when using vty100 £¬ the
work becoming hard.


zentara

2006-09-14, 8:01 am

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com