Article View: comp.os.msdos.programmer
Article #3928Re: wait for a keystroke
From: Brian K. W. Hook
Date: Sat, 15 Dec 1990 00:37
Date: Sat, 15 Dec 1990 00:37
33 lines
1374 bytes
1374 bytes
I had the same problem with a flight simulatr that I had been writing.
If you are using Turbo C, the following code should do the trick:
if (kbhit())
ch=getch()
else {
dostuff()
}
with QuickC I believe that you use kbdhit(). these check the keystroke
buffer for a key hit. Also, check out _bios_keybrd() (QC) and bioskey()
under TC.
If you want to just get the last key pressed and flush the buffer of other
keystrokes, the following will work under turbo C.
#include <bios.h>
int getLastKeyPressed ( void )
{
int chTemp;
while (bioskey(1)!=0) {
chTemp=getch();
if (bioskey(1)==0)
return chTemp;
}
}
Note that getch() will return a 0 if an extended key was pressed (ie.
F1-F12, arrow keys, page up, etc.) and that you must then do an other
getch() to get the scan code (most PC programming books have this in
them).
Technical Details
Message-ID:
<25931@uflorida.cis.ufl.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!wuarchive!emory!gatech!uflorida!reef.cis.ufl.edu!jdbReferences:
<1990Dec7.151624.19695@infonode.ingr.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!wuarchive!emory!gatech!uflorida!reef.cis.ufl.edu!jdb From: jdb@reef.cis.ufl.edu (Brian K. W. Hook) Newsgroups: comp.os.msdos.programmer Subject: Re: wait for a keystroke Message-ID: <25931@uflorida.cis.ufl.EDU> Date: 15 Dec 90 00:37:26 GMT References: <1990Dec7.151624.19695@infonode.ingr.com> Sender: news@uflorida.cis.ufl.EDU Organization: UF CIS Dept. Lines: 33