Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!ames!ucsd!sdcsvax!ucsdhub!sdsu!turtle From: turtle@sdsu.UUCP (Andrew Scherpbier) Newsgroups: comp.unix.questions Subject: Re: a question about using curses lib Message-ID: <2931@sdsu.UUCP> Date: 20 Feb 88 16:43:43 GMT References: <7078@oberon.USC.EDU> Reply-To: turtle@sdsu.UCSD.EDU (Andrew Scherpbier) Distribution: na Organization: San Diego State University, Math/Sciences Dept. Lines: 36 In article <7078@oberon.USC.EDU> xwu@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