Date: Sun, 17 Jan 1999 18:37:23 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Simon cc: djgpp AT delorie DOT com Subject: Re: Flusing keyboard buffer In-Reply-To: <36A20315.588B@magicsoftware.freeserve.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Sun, 17 Jan 1999, Simon wrote: > > while (kbhit ()) > > getkey (); > > I meant to say that if the buffer contains keystrokes that were from > some time ago and I want to totally disregard them and wait for new > presses. I want do some code such as: > > //flush old unwanted keys > flush_kb_buffer(); > //wait for new presses > while (kbhit ()) > getkey (); I'm not sure I understand what you are after. I think that the while loop I suggested does exactly what you wanted, i.e. it removes any pending keystrokes from the keyboard buffer. When the buffer is empty, the loop will be terminated. You can then start a new loop that waits for the user to press a key, like this: while (kbhit ()) getkey (); while (!kbhit ()) __dpmi_yield (); /* idle waiting for the user to press a key */ /* They pressed a key; get it. */ key = getkey (); Of course, if the user presses a key while you are in the first loop, that key will be lost. AFAIK, there's nothing you can do about that, though (unless you hook the keyboard and process the interrupts yourself), since the keypresses don't come with any time information which you could use to know whether this is an ``old'' or a ``new'' keypress.