a question about using curses lib

Chris Calabrese[rs] cjc at ulysses.homer.nj.att.com
Tue Feb 23 02:45:07 AEST 1988


In article <2931 at sdsu.UUCP>, turtle at sdsu.UUCP (Andrew Scherpbier) writes:
> In article <7078 at oberon.USC.EDU> xwu at pollux.usc.edu (Xinhua Wu) writes:
> >I'm writing a program using curses lib.  I want to use function keys (eg,
> >use arrow keys to choose from a menu).  The program should work for different
> 
> (I do not know if the following holds true for BSD 4.*, I only have access
> to Xenix V.2 and SysV.3)
> Yes, there is a function called `keypad()'.  The call should look someting
> like this:
> 	keypad(stdscr,TRUE);	/* the 'TRUE' is to enable keypad mode */


Keypad is a feature of the Terminfo terminal independant
input and output database.  Essentially the system keeps
keyboard maps around so that various terminals will all
map to one standard.

Unfortunately, BSD unix does not have Terminfo, it has termcap
instead, so it doesn't have keypad().  The way to get
arround this is to assume that the arrow keys (and home keys, etc)
return the same escape sequences as the corresponding screen
functions.  In other words, the up arrow probably returns the
sequence which moves the cursor up, etc.  These output
codes are kept in the termcap database, and the termcap
library can be used to bring them out and test for them.

Of course, the above idea will not produce portable code, so
you should include things like:

#if _TermCap
...
#else
#if _TermInfo
...
#endif
#endif

In the dependant code.


	Christopher Calabrese
	AT&T Bell Laboratories
	ulysses!cjc



More information about the Comp.unix.questions mailing list