[comp.sys.ibm.pc.programmer] Slow kbhit

c60b-hk@buddy.Berkeley.EDU (Geoffrey Broadwell) (02/19/90)

I just caught an article referring to the fact that kbhit() is annoyingly
slow.  I have noticed this myself, and came up with the following function
that responds quite a bit faster (I'm sure someone will one-up its speed,
but what the hell -- it's simple! :-) ).

char keypress(void)
{
 _AH=0x01;
 geninterrupt(0x16);
 return(~_FLAGS&0x40);
}

I wrote it using TurboC 2.0, so if your compiler is different, the syntax
is probably somewhat different, though it should be easily translatable.
Good luck.
BTW, I would be interested in being one-upped, if anyone is willing. :-)

					-'f
					(Geoffrey Broadwell)

pipkins@qmsseq.imagen.com (Jeff Pipkins) (02/20/90)

In article <22242@pasteur.Berkeley.EDU> c60b-hk@buddy.Berkeley.EDU.UUCP (Geoffrey Broadwell) writes:
>I just caught an article referring to the fact that kbhit() is annoyingly
>slow.  I have noticed this myself, and came up with the following function
>that responds quite a bit faster (I'm sure someone will one-up its speed,
>but what the hell -- it's simple! :-) ).
>
>char keypress(void)
>{
> _AH=0x01;
> geninterrupt(0x16);
> return(~_FLAGS&0x40);
>}
>
>I wrote it using TurboC 2.0, so if your compiler is different, the syntax
>is probably somewhat different, though it should be easily translatable.
>Good luck.
>BTW, I would be interested in being one-upped, if anyone is willing. :-)

I haven't heard complaints of kbhit() being slow, but I rewrote kbhit()
and several other related functions (including getch(), getche(), ungetch(),
and putch() ) because of several deficiencies in the ones that come with
the MSC compiler.  These are written in assembly, callable from MSC or
Turdo C.  The commented source code, along with documentation in similar
format to that of the MSC lib. ref, has apparently been uploaded to SIMTEL,
it is in PD:<MSDOS.C>CONIO.ARC.  The C User's Journal also has it on file.
If none of these are accessible, I will be glad to e-mail a copy to anyone
sending a request to pipkins@imagen.com.  Please include an '@'-style
return address, as '!' (bang) addresses are often uni-directional.  Also,
I can't send to *.UUCP addresses.

-Jeff Pipkins
pipkins@imagen.com