ReadKey like Function in C

Kevin_P_McCarty at cup.portal.com Kevin_P_McCarty at cup.portal.com
Thu Aug 17 19:05:48 AEST 1989


In <10746 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>Terminal input is a more difficult matter to deal with than output
>buffering, because of the necessity to deal with mode switches (from
>input cnanonicalizing to non-canonicalizing) in many environments.
>The reason input canonicalization is done is of course to allow humans
>to correct typical typing errors before their input is received by
>applications; otherwise every application would have to take care of
>it, which is obviously poor software design.
>
>kbhit() and getch() are a poor model for such an environment.

Agreed, except that such an environment, with its canonicalized input,
does not encompass every application.  Such an environment is not the
only one for which C programs are written.  kbhit() and getch() are
appropriate for low level control of a mechanical control device called
a keyboard.  The physical similarity of a keyboard in this environment
to a keyboard used as a text entry device in the traditional environment
is mostly coincidental.

Programming with kbhit() and getch() is programming for an embedded
system, where keyboard input is event oriented rather than text
oriented, and is handled in the same fashion as mouse, joystick or
pushbutton input, for example for cursor movement or one-key mode
switching.  Examples would be games and other visual simulations, using
PCs as hardware controller or test instrument consoles, prototyping of
things like ATM terminals, microwave ovens, VCRs or what have you.
These are not really environments which you would call hosted, even
though other services a hosted environment provides are present.

This miscellaneous collection of applications lies in the single user,
single tasking region somewhere between microcontrollers running
embedded firmware and Real Computer Systems (tm) running a Real
Operating System (tm).  Somewhere closer to the former than the latter.
This area was opened up by the personal computers from IBM and others,
where the operating system is barely a command line with a file system
on top of a BIOS.

It is mostly programmers writing applications suited for these
rudimentary platforms who need kbhit() and getch().  They only need them
for embedded system types of programs, not for any applications which
have a hope of porting elsewhere.

kbhit() and getch() work suitably well wherever they appear, and they
seem to appear wherever they are suitable.  I see no need to go beyond
the current state of affairs.  Just because they are useful for some
kinds of programming is no reason to canonize them into the language for
everybody.  (It should be noted that library functions are not guaranteed
to be available in a non-hosted environment anyway.)

Kevin McCarty



More information about the Comp.lang.c mailing list