How do you read the arrow keys?

Michael Meissner meissner at osf.org
Sat Dec 29 04:39:23 AEST 1990


I tried mailing to icsu7039 at nero.cs.montana.edu, but got a mail
bounce:

| From: icsu7039 at nero.cs.montana.edu (Spannring)
| Newsgroups: comp.unix.programmer
| Date: 27 Dec 90 19:20:24 GMT
| Organization: Montana State University, Dept. of Computer Science, Bozeman
| 
| 
|     I am currently porting some menu routines from MS-DOG to Unix.  
| What is the proper (terminal independent) way of reading the arrow
| and/or function keys?

If your vendor's curses package is based on System V.2 then that is
provided.  If you have the old broken BSD curses, lots of luck -- you
can read what the function keys send with tgetstr and the capabilities
kd, ku, kl, and kr for the arrow keys -- you will have to do the
parsing yourself.

Quoting from the manual on curses:

     int getch ( void );
          Get a character from stdscr. May be used with mini-
          curses.  The following function keys might be returned
          by the getch() function if keypad() has been enabled:

          KEY_BREAK Break key (unreliable)

          KEY_DOWN  Down arrow key

          KEY_UP    Up arrow key

          KEY_LEFT  Left arrow key

          KEY_RIGHT Right arrow key

          KEY_HOME  Home key

          KEY_BACKSPACE
                    Backspace (unreliable)

          KEY_F(n)  Function key Fn, where n is an integer from 0
                    to 63

          KEY_DL    Delete line

          KEY_IL    Insert line

          KEY_DC    Delete character

          KEY_IC    Insert character or enter insert mode

          KEY_EIC   Exit insert character mode

          KEY_CLEAR Clear screen

          KEY_EOS   Clear to end of screen

          KEY_EOL   Clear to end of line

          KEY_SF    Scroll one line forward

          KEY_SR    Scroll one line backwards (reverse)

          KEY_NPAGE Next page

          KEY_PPAGE Previous page

          KEY_STAB  Set tab

          KEY_CTAB  Clear tab

          KEY_CATAB Clear all tabs

          KEY_ENTER Enter or send (unreliable)

          KEY_SRESET
                    Soft (partial) reset (unreliable)

          KEY_RESET Reset or hard reset (unreliable)

          KEY_PRINT Print or copy

          KEY_LL    Home down or bottom (lower left)

          KEY_A1    Upper left key of keypad

          KEY_A3    Upper right key of keypad

          KEY_B2    Center key of keypad

          KEY_C1    Lower left key of keypad

          KEY_C3    Lower right key of keypad

          Due to lack of definitions in terminfo, or due to the
          terminal not transmitting a unique code when the key is
          pressed, not all of these keys are supported.

	...

     int keypad( WINDOW *win, bool bool_flag );
          Enable keypad input on window win if bool_flag is true.
--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?



More information about the Comp.unix.programmer mailing list