Path: utzoo!dciem!nrcaer!xios!greg
From: greg@xios.XIOS.UUCP (Greg Franks)
Newsgroups: comp.lang.c
Subject: Re: Using arrow keys with curses.
Message-ID: <535@xios.XIOS.UUCP>
Date: 16 Jun 88 12:38:59 GMT
Article-I.D.: xios.535
References: <485@cieunix.rpi.edu> <1162@mcgill-vision.UUCP>
Reply-To: greg@sdn.UUCP (Greg Franks)
Distribution: na
Organization: XIOS Systems Corporation, Ottawa, Ontario, Canada
Lines: 53

In article <1162@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP (der Mouse) writes:
>In article <485@cieunix.rpi.edu>, curt@cieunix.rpi.edu (Curt Signorino) writes:
>> I've also been trying to access the arrow keys with curses, but
>> haven't quite got the hang of it.  What I'd had in mind was doing a
>> getchar() and then switching on the appropriate value of the arrow
>> key to the cursor moving routines.
>
>Arrow keys generally send multi-character sequences; doing just one
>getchar() will get just one character.  You'd need to look up the
>sequences the arrow keys send somewhere (termcap has capabilities for
>this: kl, kr, kd, ku).  Then if they are more than one character long,
>you will need to call getchar() multiple times and parse the results
>somehow.  It's not simple.
>

I don't know whether the original author stated which version of UNIX he
was on....

Sys V curses handles the arrow (and other function keys) automagically. 
Here are some code segments...

		initscr();		/* read terminfo database 	*/
		cbreak();		/* Cbreak mode.			*/
		noecho();		/* Don't echo chars		*/
		keypad( stdscr, 1 );	/* But do allow keypad ops	*/
		typeahead( 0 );		/* Allow typeahead.		*/

...
		int c;			/* NOT char!!!! */

		c = wgetch( stdscr );

		switch( c ) {

		case KEY_RIGHT: case 'L': case 'l':
		case KEY_DOWN:	case 'J': case 'j':
			cursor = curr_menu[cursor].next;
			break;

		case KEY_LEFT:	case 'H': case 'h':
		case KEY_UP:	case 'K': case 'k':
			cursor = curr_menu[cursor].prev;
			break;


**IMPORTANT** Don't use getc() or friends.  Use the curses equivalent. 
I don't know if this stuff is in Berkeley.

Good luck!
-- 
Greg Franks                   XIOS Systems Corporation, 1600 Carling Avenue,
utzoo!dciem!nrcaer!xios!greg  Ottawa, Ontario, Canada, K1Z 8R8. (613)725-5411.
   ACME Electric: When you can't find your shorts, call us!