Key management problem (ncurses) [Archive] - C Board

PDA

View Full Version : Key management problem (ncurses)


wookie
10-04-2003, 05:12 AM
I wrote this to show what the problem is :


#include <ncurses.h>

#define ESC 27


int main ()
{
int x = 0;

initscr ();
keypad (stdscr, TRUE);
cbreak ();

while (x != ESC)
{
clear ();
printw ("%d", x);
x = getch ();
}

endwin ();
return 0;
}


So, pressing any key makes it's code appear on the screen. However, pressing the HOME or END keys exits the program at once. Pressing the ESC key also exits the program, but with a delay of about a second.

What should I change to make it run right (ECS exits immediately, HOME/END prints the keycode)?

Thanks in advance.

Hammer
10-04-2003, 04:41 PM
For the delay in processing escape, try this environment variable:

export ESCDELAY=0

Haven't had cause to use it myself, so I'd recommend you research it properly if you want to know why it's there in the first place.

a_sankar
10-16-2003, 02:17 AM
In ncurses,Scan codes for function keys,Esc etc have been defined with values greater than 256 (U cant use char variable to capture them).
To get ur program right , change the contition as

while ( x!=KEY_ESC) //KEY_ESC for Esc key