HOW do I clear the Keyboard Buffer??? 
Author Message
 HOW do I clear the Keyboard Buffer???

What is the code to clear the Keyboard Buffer in Qbasic??

I know it has something to do with PEEK and POKE.

Thanks in advance.

P.S. I think this one is a toughy!



Sun, 07 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???


Quote:
>What is the code to clear the Keyboard Buffer in Qbasic??

>I know it has something to do with PEEK and POKE.

>Thanks in advance.

>P.S. I think this one is a toughy!

The easiest way is to build a small SUB that you can call from anywhere in
your program.

SUB ClearKeyboard

  DO
    K$ = INKEY$
  LOOP UNTIL LEN(K$) = 0

END SUB

Works like a charm! :)

   ____    _    ____      ____  _____
  |  _ \  / \  / ___) __ | ___)(_   _) Don Schullian

  |____//_/ \_\(____/\__/|_|     |_|    www.DASoftVSS.com
  ___________________________________   www.basicguru.com
      Vertical Software Solutions



Sun, 07 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

AP>What is the code to clear the Keyboard Buffer in Qbasic??
AP>I know it has something to do with PEEK and POKE.

   You could use Peek and Poke, but why when you can do it in QBASIC.

AP>P.S. I think this one is a toughy!

   DO
    Anykey$ = INKEY$
   LOOP UNTIL AnyKey$ = ""   ' Loop till no keys in buffer

   Only tough until you know the answer! :) Hope that helps. Good luck!

-Robert Fortune

 * OLX 2.1 TD * "Don't ask, don't tell."



Sun, 07 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

Quote:

>SUB ClearKeyboard

>  DO
>    K$ = INKEY$
>  LOOP UNTIL LEN(K$) = 0

>END SUB

>Works like a charm! :)

True, but this is a lot faster:

SUB ClearKeyboard
        DEF SEG = 0
        POKE 1050, 30
        POKE 1052, 30
END SUB

No need for up to 15 conditional loops, just a single POKE...
--
Marc van den Dikkenberg
--
The powerbasic Archives (EU) -- http://www.xs4all.nl/~excel/pb.html
The PowerBasic Archives (US) -- http://www.basicguru.com/dikkenberg
All Basic Code Archives      -- http://come.to/abcpackets



Mon, 08 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

Quote:

>AP>What is the code to clear the Keyboard Buffer in Qbasic??
>AP>I know it has something to do with PEEK and POKE.

>   You could use Peek and Poke, but why when you can do it in QBASIC.

...Because it works just as well, but also is a lot faster?

(QBasic is slow enough already, compared to modern BASIC's ;-)
--
Marc van den Dikkenberg
--
The PowerBasic Archives (EU) -- http://www.xs4all.nl/~excel/pb.html
The PowerBasic Archives (US) -- http://www.basicguru.com/dikkenberg
All Basic Code Archives      -- http://come.to/abcpackets



Mon, 08 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

AP>What is the code to clear the Keyboard Buffer in Qbasic??
AP>I know it has something to do with PEEK and POKE.

RF> You could use Peek and Poke, but why when you can do it in QBASIC?

MVDD>....Because it works just as well, but also is a lot faster?

    Really? Have you benched both methods? Here's some simple code
    to test both methods. The results on my Pentium 90 show both
    methods to be the same or the DO/LOOP to be the faster.

' ----------- CUT HERE ------------------ CUT HERE -----------------------
REM TIMEONE.BAS
REM Marc Van Den{*filter*}kenberg
'    ---------------- Test code part I -------------------------
DECLARE SUB ClearKeyboard ()
CLS
PRINT
Synch! = TIMER      ' synchronize to TIMER
DO
  Start! = TIMER
LOOP WHILE Start! = Synch!

FOR I% = 1 TO 10000      ' do ten thousand times
    ClearKeyboard
NEXT I%

Done! = TIMER
Test1! = Done! - Start!
PRINT Test1!
'    -----------------Test code part II -------------------------
REM TIMETWO.BAS
REM Robert Fortune
Synch! = TIMER                ' synchronize to TIMER
DO
  Start! = TIMER
LOOP WHILE Start! = Synch!
FOR I% = 1 TO 10000           ' do ten thousand times
    DO
       AnyKey$ = INKEY$
    LOOP UNTIL AnyKey$ = ""
NEXT I%
Done! = TIMER
Test2! = Done! - Start!
PRINT Test2!
END

SUB ClearKeyboard
        DEF SEG = 0
        POKE 1050, 30
        POKE 1052, 30
END SUB
' ----------- CUT HERE ------------------ CUT HERE -----------------------

MVDD>(QBasic is slow enough already, compared to modern BASIC's ;-)

      On my PC, QBASIC as well as QB and PDS are quicker than the
      eye can see. Of course if I choose to use PDQ then they are even
      smaller and faster (in many cases). :)

-Robert Fortune

 * OLX 2.1 TD * "Some call it heavenly in its brilliance."



Mon, 08 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

Quote:


>>SUB ClearKeyboard

>>  DO
>>    K$ = INKEY$
>>  LOOP UNTIL LEN(K$) = 0

>>END SUB

>>Works like a charm! :)

>True, but this is a lot faster:

>SUB ClearKeyboard
>    DEF SEG = 0
>    POKE 1050, 30
>    POKE 1052, 30
>END SUB

>No need for up to 15 conditional loops, just a single POKE...

Yea but in some versions of PB that little trick doesn't clear PB's counter
and then things REALLY get screwy! I've not tried the PEEK/POKE in some time
so it may be fixed but......

C'ya,

   ____    _    ____      ____  _____
  |  _ \  / \  / ___) __ | ___)(_   _) Don Schullian

  |____//_/ \_\(____/\__/|_|     |_|    www.DASoftVSS.com
  ___________________________________   www.basicguru.com
      Vertical Software Solutions



Mon, 08 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???


|>
|> >SUB ClearKeyboard
|> >  
|> >  DO
|> >    K$ = INKEY$
|> >  LOOP UNTIL LEN(K$) = 0
|> >
|> >END SUB
|> >
|> >Works like a charm! :)
|>
|> True, but this is a lot faster:
|>
|> SUB ClearKeyboard
|>   DEF SEG = 0
|>   POKE 1050, 30
|>   POKE 1052, 30
|> END SUB
|>
|> No need for up to 15 conditional loops, just a single POKE...

I have used this method. As you know, it resets the head of the
keyboard buffer to be idntical to the tail of the buffer. This
"throws away" any contents in the circular buffer. I have been told
(and it makes good sense to me) that this method has a weakness.

This method relies of the keyboard buffer being located in the
same 16 bytes specified in the original IBM PC. Some users found
they would type too fast and fill up the buffer (especially when
the program failed to pull keystrokes because it was performing
a calculation and was too busy).

Starting with the IBM AT, you can't be sure whether or not the user
has created a larger keyboard buffer located elsewhere in memory. If
keystrokes are sitting outside thenormal buffer space, the method you
show here won't empty them.

--
Brian McLaughlin, Technical Writer  |"Thanks to the Internet, misinformation
Integrated Measurement Systems, Inc.| now travels faster than ever before!"
Beaverton, OR, USA                  | ---- Standard disclaimer applies ----



Mon, 08 Oct 2001 03:00:00 GMT  
 HOW do I clear the Keyboard Buffer???

shell to this

                        ........
                                clear keyboard buf      
                        ........

                -------------------------------

                http://oak.oakland.edu/simtel.net/

                batchutl/
clrkey13   10280  921129  CLEAR 'n' keystrokes from KEYBOARD BUFfer

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+



Tue, 09 Oct 2001 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Clearing the keyboard buffer

2. clearing the keyboard buffer

3. How do you clear the keyboard buffer?

4. Does Internet Explorer Clear the Keyboard Buffer?

5. Mouse/keyboard buffer clear ...possible ?

6. Clear the keyboard type-ahead buffer in VB

7. how do I clear the keyboard buffer from the VB 5.0

8. How do I clear the keyboard buffer in vb 5.0

9. Clear keyboard buffer?

10. How do I clear keyboard buffer in VB 5.0

11. How to clear keyboard buffer?

12. How to clear keyboard buffer ?

 

 
Powered by phpBB® Forum Software