[comp.lang.c] Keypress detection

ed@zaphod.uchicago.edu (Ed Friedman) (08/05/89)

Does anyone have a routine in C which will allow the program to detect
a keypress without reading in the key?  I am trying to avoid the use
of getch() which would hang the program forever until a key is pressed.

Thanks in advance,
Ed Friedman

ed@zaphod.uchicago.edu
friedman@uchicago.bitnet

fredex@cg-atla.UUCP (Fred Smith) (08/07/89)

In article <4850@tank.uchicago.edu> ed@zaphod.uchicago.edu (Ed Friedman) writes:
>Does anyone have a routine in C which will allow the program to detect
>a keypress without reading in the key?  I am trying to avoid the use
>of getch() which would hang the program forever until a key is pressed.
>
>Thanks in advance,
>Ed Friedman
>
>ed@zaphod.uchicago.edu
>friedman@uchicago.bitnet




------------------

If you are programming on a PC or clone, the easy way to do it in Microsoft C
is to use the routine _bios_keybrd, which has a number of options. You can
also use (in many PC implementations including MS) the routine kbhit().

If you are in the PC or clone environment but don't have either of
those available you can do a call to INT 0x10. You should set the
AH register to 1. When it returns the ZeroFlag will be clear if there
is a character waiting, and will be set if there is NOT a character waiting.
You can then read any subsequent characters in the normal fashion. (whatever
that might be for you.)

If you are not in the PC environment, then all bets are off. It will be
necessary for some guru in your environment to advise you.

Fred Smith