Qbasicnews.com

Full Version: Lost keys in buffer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've noticed that if I use:
Code:
DO UNTIL INKEY$=key1$
IF INKEY$=key2$ THEN
  '...do some stuff
END IF
LOOP
Sometimes, when you press key2$, it doesn't get pushed into the keyboard buffer. But key1$ doesn't have any problem with this.
Why is this? And can I fix it?
Yeah, you can. The problem is that reading INKEY$ clears the buffer, so maybe your key gets kicked out of it.

The sollution is assign a variable and read from it, it will retain the correct value and won't be pushed out in each "IF".

Code:
DO
   k$= INKEY$
   IF k$ = key2$ THEN
      '... do some stuff
   ENDIF
LOOP UNTIL k$ = key1$
Thanks.
Now that I think of it, though, this should have gone in "Newbie Questions".
I'm a born-again QBer, heh. Ah, well.