Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? What's the definitive way to clear the keyboard buffer? [answer: inkey /c works fine]

Jul
534
10
EDIT: This problem is solved. Inkey /c is definitely working.

————————————————————

inkey /C doesn't seem to actually be clearing the keyboard buffer anymore. I'm looking for more-generalized command-line solutions to do this. Hoping to not have to go into Python/Perl for speed reasons.

Tired of blowing past my pauses and having my inputs pre-filled by errant keystrokes out despite adding the /C before hand. Even tried to repeat it 100 times in case it was just clearing 1 character. Nope.
 
Last edited:
This is a solution for cmd.exe,
see if it will work for you in TCC;
Code:
echo off > nul
pause > nul

Alternatives to this method no doubt exist,
so YMMV.

Joe
 
This is a solution for cmd.exe,
see if it will work for you in TCC;
Code:
echo off > nul
pause > nul

Alternatives to this method no doubt exist,
so YMMV.

Joe
That doesn't work for me. At all.

1731089209395.webp
 
Yea, I think my problem was i was using inPUT instead of inKEY. Seemed to work forever until recently. But maybe recently i changed it from inKEY to inPUT errantly.

Well, mystery solved. PEBKAC yet again.
 
Shouldn't the INPUT command option /C also clear the buffer. It doesn't seem to work in TCC32. The help says:

/CDiscard any keystrokes pending in the keyboard buffer before INPUT begins accepting characters.

Here's my version of the test:

Code:
[TCC32.10.21 | C:\temp]
>type test.btm
echo Waiting 5 seconds; type away.
delay 5
input /c Enter text: %%text
echo Variable text = %text

[TCC32.10.21 | C:\temp]
>test.btm
Waiting 5 seconds; type away.
Enter text:dfsdfTEST
Variable text = dfsdfTEST

During the 5-second delay, I typed "dfsdf". I would have expected that to be cleared when the input /c was run, but those characters appeared on the screen after the prompt. I then entered "TEST" to see if only that string or the entire string shown would be stored in the variable. The latter was the case. The keyboard buffer was not cleared.
 
Indeed it does. I think somehow my inkey got changed to input...
 
The help is incorrect; the /C option only works if it is the only argument for INKEY or INPUT. Allowing other arguments is on the suggestion list for v34.
Not for INPUT. It gives an error message and nothing in cleared. Below, I typed during the delay.

Code:
v:\> delay 5 & input /c
Usage : INPUT [/C /D /E /K"keys" /Lx[:y] /N /P /Wn /X] [prompt ] %%varname

v:\> hghghghgh
 
A bit of trickery ... if you never want previously typed characters showing up after a new prompt, you could (not tested much) ...

Code:
set prompt=%%@exec[@inkey /c]%prompt
 
oh my that's a great idea, though i do type ahead sometimes haha :)
 
The help is incorrect; the /C option only works if it is the only argument for INKEY or INPUT. Allowing other arguments is on the suggestion list for v34.
I do believe this was my problem. I was reading it into a dummy variable who's name was basically a comment about what was being done (%this_clears_out_the_keyboard_buffer%) .... Then at some point I changed it from inkey to input in frustration. Then at some point I forgot i changed it to input and became even more confused.
Thanks!
 
Back
Top