Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you clear the input buffer?

Status
Not open for further replies.

sandmann999

Programmer
Apr 28, 2001
52
US
I have a game where you use the arrow keys to control your figure arround the screen. Every time you press the arrow key, it calculates a lot of things (besides your characters movement) so meanwhile it loads up a lot of direction presses in the buffer and eventually locks up for a few seconds until they are all used. (Hopefully that's not confusing. If it is, I'll try to reclarify.)

Here's what I do

DO
DO
X$ = INKEY$
LOOP UNTIL X$ <> &quot;&quot;
IF X$ = CHR$(0) + &quot;M&quot; THEN: (move right)
IF X$ = CHR$(0) + &quot;K&quot; THEN: (move left)
IF X$ = CHR$(0) + &quot;P&quot; THEN: (move down)
IF X$ = CHR$(0) + &quot;H&quot; THEN: (move up)
(here i have it redraw the map using data information)
LOOP

So what it does is for every 2 or 3 every times I press an arrow key, it moves my character once or twice. So the arrow key presses continually build up more than they can be processed. I know I could just press the arrow keys less, but I wouldn't want to have to say in a readme.txt telling everyone not to hold down the arrow keys when they move.

Is there any way to just clear out the arrow key presses so that it only registers them right before they're used? I know that in the C language, you just use the command FFLUSH
and that clears out all the previous keyboard input.

Does anyone know how to do it in QBASIC? Thank you in advance.
 
Earlier msdos method:
x$=inkey$
if len(x$)=0 then proceed else clear next Ed Fair
efair@atlnet.com

Any advice I give is my best judgement based on my interpretation of the facts you supply.

Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.

 
It looks like it's heading in the right direction, but PROCEED isn't a qbasic command and the NEXT gives an error message. THankyou though.
 
This was for guidance not the specifics. The proceed is to be replaced by your next label and the clear is to be replaced by the label you use for the start of the clear routine. The next was a typo , should have been clearnext. Ed Fair
efair@atlnet.com

Any advice I give is my best judgement based on my interpretation of the facts you supply.

Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.

 
Sandmann999:

Just like in your code...

IF X$ = CHR$(0) + &quot;M&quot; THEN [red](move right)[/red]


Edfair was just giving you an example...

IF LEN(X$) = 0 THEN [red](proceed)[/red] ELSE [red](clearbuffer)[/red]

Hope this clears it for you.
--MiggyD

&quot;The world shrinks more and more with every new user online.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top