Newsgroups: comp.os.msdos.djgpp Subject: Re: How to empty the keyboard buffer From: richard AT stardate DOT bc DOT ca (Richard Sanders) X-Newsreader: WinVN 0.99.9 (Released Version) (x86 32bit) References: <7tibo0$44f$1 AT rohrpostix DOT uta4you DOT at> MIME-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII NNTP-Posting-Host: wlp36.rapidnet.net Message-ID: <37fd6535_2@news.vphos.net> Date: 7 Oct 1999 20:29:57 -0800 X-Trace: 7 Oct 1999 20:29:57 -0800, wlp36.rapidnet.net Lines: 43 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > >Okay, the shortest test program is the following: > >#include >#include > >#include "allegro.h" > >int main() >{ > int c; > > allegro_init(); > install_timer(); > do > { > c = getch(); > rest(1000); > while (kbhit()) > c = getch(); > } > while (c != 27); >} I have always found it better to empty the keyboard buffer before attempting to get keystroke. This ensures that any key strokes captured were made when your program was looking for one, not some leftover stuff or someone just playing on the keyboard. Something like this. /* start empty the keyboard buffer */ while( kbhit()) getch(); /* end empty the keyboard buffer */ /* start key capture */ do { while(!kbhit()); /* loop until a key is pressed */ c=getch(); } while( c!=27 ); /* loop until the desired key is pressed */ /* end key capture */