Thread: Key management problem (ncurses)

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    Key management problem (ncurses)

    I wrote this to show what the problem is :

    Code:
    #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.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    1
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Yet another lame program -- ncurses problem
    By w00tw00tkab00t in forum C Programming
    Replies: 2
    Last Post: 01-08-2006, 02:48 PM
  2. Mouvment problem
    By Death_Wraith in forum C++ Programming
    Replies: 9
    Last Post: 06-01-2004, 06:58 PM
  3. BCB Key press problem
    By Death_Wraith in forum Game Programming
    Replies: 0
    Last Post: 05-30-2004, 03:13 PM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM