a question about using curses lib

Andrew Scherpbier turtle at sdsu.UUCP
Sun Feb 21 02:43:43 AEST 1988


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
>terminal types (vt100, xterm, ibmaed, h19, etc).
>
>My general question is: how can I make the program recognize a function key
>immediately after the user hits it?
	[The rest deleted]

(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 */
After this call, wgetch() will return special characters as described in
curses.h (ie KEY_LEFT for the left arrow key)
Be aware (I have made this mistake MANY times..) that with keypad mode enabled,
wgetch will return a character of type `chtype'.  This is normally a `short'.
Without the keypad mode, wgetch can be assumed to return only charaters of
type `char'.
Another thing to look at is the `notimeout()' call.  Normally, in keypad mode,
wgetch will set a timer.  The purpose of the timer is to differentiate between
sequences received from a function key and those typed by a user' [from ATT Unix
System V Programmer's Reference Manual, page 437]
The call to `notimeout()' looks like this:
	notimeout(stdscr,TRUE);	/* this will turn OFF the delay timer feature */

Happy hacking,

-Andrew

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~T~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"I sometimes get the feeling that   |  Andrew Scherpbier
 things cannot possibly get worse...|  Computer Science Department
 and sure enough, they do."         |  San Diego State University
	-Don Perkins Jr.            |  ihnp4!jack!sdsu!turtle



More information about the Comp.unix.questions mailing list