Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!uunet!xstor!ivy!iverson From: iverson@ivy.uucp (Tim Iverson) Newsgroups: comp.unix.programmer Subject: Re: How do you read the arrow keys? Message-ID: <1990Dec28.195518.26577@ivy.uucp> Date: 28 Dec 90 19:55:18 GMT References: <3080@dali> Organization: Storage Dimensions, Inc. Lines: 33 In article <3080@dali> icsu7039@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 [D, so if your user hits , curses waits for the next char to come along before it knows to return the 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@caesar.cs.montana.edu - Tim Iverson uunet!xstor!iverson