ReadKey like Function in C

Peter da Silva peter at ficc.uu.net
Thu Aug 24 01:51:38 AEST 1989


In article <9322 at chinet.chi.il.us>, kdb at chinet.chi.il.us (Karl Botts) writes:
> into the world of terminals which has not been discussed in this
> discussion.  [details of the problems of function keys on ASCII terminals]

> But making a
> kbhit() routine that only returns keyboard bytes doesn't accomplish
> anything -- it leaves the programmer still with the same problem.

Well, that's a good explanation of a problem with routines like kbhit(),
but for many applications the problem can be ignored. For example, a
readch() or testch() routine may not be dealing with a keyboard at all.
Or the application may just want to get a yes/no response.

Also, even if you solve the problem of function keys you have the problem
of portable screen output. Fortunately this is a solved problem in UNIX
with Ken Arnold's "curses" library. Implementations of curses for MS-DOS
exist, as well. Coincidentally, this solution also provides ReadKey(),
and handles function keys with a timeout (as you described).

Curses makes a good addition to the semi-standard C toolbox.

Unfortunately, this is overkill for many applications, and completely
inappropriate for others, such as a file transfer program. Something
lower level is still desirable.
-- 
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
"The security biz is subtle, you have to pick your trade-offs carefully."   U
	-- Barry Shein



More information about the Comp.std.c mailing list