How do you read the arrow keys?

Tim Iverson iverson at ivy.uucp
Sat Dec 29 06:55:18 AEST 1990


In article <3080 at dali> icsu7039 at nero.cs.montana.edu (Spannring) writes:
>    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?

Reading special keys is relatively easy - just look up the arrow/function
key definitions you wish to interpret in termcap or terminfo (whichever
your users are more likely to be using) and decode them as they come in.

The most general way to decode them is to build a key fetching FSM that
represents the current terminal and then ask it for keys; it, in turn,
gets byte strings from the terminal and turns them into keys.

There're going to be alot of responses about getting curses to decode your
keys for you.  And, yes, it will do it, but it has a major problem: no
timeouts; e.g. left arrow on a vt100 (or pc ansi console) is <esc>[D, so if
your user hits <esc>, curses waits for the next char to come along before
it knows to return the <esc> as a key.

This is a failing of every package I've seen that purports to handle arrow
keys in a device independent manner, although, it's such a basic problem
that I assume someone somewhere is offering a package that does do it right.

Marc Rochkind has a good book on terminal style I/O (Advanced C Programming
for Displays) that covers all of the pieces of a comprehensive screen I/O
library, read it, but don't use the C code - each piece lacks some major
feature (like early prefix recognition for key input).

> Six of one, 110 (base 2) of       | Craig Spannring
> another.                          | icsu7039 at caesar.cs.montana.edu

- Tim Iverson
  uunet!xstor!iverson



More information about the Comp.unix.programmer mailing list