|
From: | Mauricio Amorim da Silva |
Subject: | Tip curses |
Date: | Sun, 07 Oct 2001 13:21:10 -0300 |
I did an program in C (now i are doing in Perl),
that use getch (or wgetch), for read keys from terminal.
In any situations, the terminal return more that
one sequence of characters, when the termcap or terminfo database is not
properly configured.
A did an little piece of code that use getch, but
don't display that sequences.
I don't if exist other manner if did it, apparently
was useful.
The piece is displayed below in perl and in c:
IN PERL:
#-------------------------------------------------------
# getkey
#
# Params: window
#-------------------------------------------------------
sub getkey
{
my
($window) = shift;
$window
= $mainwindow unless defined $window;
local
$numsequences = 0;
local
$key, $otherkey;
nodelay($window,
0);
$key
= wgetch($window);
$numsequences++;
nodelay($window,
1);
$numsequences++
while (($otherkey = wgetch($window)) != ERR);
nodelay($window,
0);
return(-1)
if ($numsequences != 1);
return($key);
}
IN C:
#-------------------------------------------------------
# getkey
#
# Params: window
#-------------------------------------------------------
chtype getkey (WINDOW
* window)
{
int
numsequence = 0;
chtype
key, otherkey;
nodelay(window,
FALSE);
key
= wgetch(janela);
numsequence++;
nodelay(window,
TRUE);
while
((otherkey = wgetch(window)) != ERR)
numsequence++;
nodelay(window,
FALSE);
if
(numsequence != 1)
return(-1);
else
return(key);
}
bye, Mauricio
[Prev in Thread] | Current Thread | [Next in Thread] |