Using arrow keys with curses.

Lawrence F. Strickland larry at jc3b21.UUCP
Tue Jun 14 21:28:23 AEST 1988


>From article <1162 at mcgill-vision.UUCP>, by mouse at mcgill-vision.UUCP (der Mouse):
> In article <485 at cieunix.rpi.edu>, curt at cieunix.rpi.edu (Curt Signorino) writes:
>> I've also been trying to access the arrow keys with curses, but
>> haven't quite got the hang of it.  What I'd had in mind was doing a
> 
> Arrow keys generally send multi-character sequences; doing just one
> getchar() will get just one character.  You'd need to look up the

Of course, it goes without saying that if you are using System V.2.0.4 or
later, curses comes with a routine (wgetch) that picks up these as
'extended' key codes (KEY_UP, etc).  However, if you use BSD 4.2 routines
or if you use XENIX (SCO style) or other earlier systems, this doesn't
work.

I use most of the above at one time or another during the day, so I came up
with a set of functions (getkeys and wgetch) that could be linked with your
program to simulate the latter curses.  It uses the same key definitions so
that it is compatible with curses and works with the various versions of
SCO XENIX as well (these were the HARDEST to get to work!)

Unfortunately, the algorithm I use is somewhat slow and with slower
processors (notably the AT&T 3b2/300) it is prone to lose characters
occasionally.  In my defense, so is vi in the same circumstances.  On
faster processors, I've had little trouble.

The same routine(s) were installed in Micro-EMACS 3.9e to make a version
that works with curses/termcap/terminfo instead of against it so that
cursor control and function control keys will work under UNIX.

If anyone is interested, I could probably post the routines to
comp.sources.misc or alt.sources or whatever.  Please let me know.  They
are fairly short.

-l
-- 
+--------------------------------------+-- St. Petersburg Junior College --+
|        Lawrence F. Strickland        |   P.O. Box 13489                  |
| ...gatech!codas!usfvax2!jc3b21!larry |   St. Petersburg, FL 33733        |
+-(or) ...gatech!usfvax2!jc3b21!larry -+-- Phone: +1 813 341 4705 ---------+



More information about the Comp.lang.c mailing list