Welcome!

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

SignUp Now!

WAD Version 34: INPUT /C Throws an Error When Used Alone

Jun
760
16
Code:
>inkey /c
Usage : INKEY [/C /D /K"keys" /M /P /Wn /X] [prompt ] %%varname
 
Sorry, I gave the example for INKEY. The problem is in both.

Because of the previous restriction, I have a lot of scripts that have the command with the /C option alone followed by the one to get the input. They are now throwing errors.
 
You choices are to have /C work only by itself, or in combination with other options. You had said previously that you wanted to use it in combination, so that's what I did in v34.

Doing both will require a major rewrite of INPUT & INKEY. If you want me to change it back to the old approach, I can do that now during the beta.
 
You choices are to have /C work only by itself, or in combination with other options. You had said previously that you wanted to use it in combination, so that's what I did in v34.

That's right, but I didn't say that it should not work alone.

Is it really such a major rewrite to detect the case where the argument is only /C and clear the buffer? The syntax would then be:

Format: INKEY /C
INKEY [/= /C /D /K"keys" /P /M /T /Wn /X] [prompt] %%varname

In any case, the way you have it now is fine. Thank you very much for making the change.

I can easily search through my scripts and combine the pairs of INKEY and INPUT commands into a single one. That will be fine so long as I'm using version 34 (or I can add code in the scripts to detect the version of TCMD and perform the appropriate commands).
 
Given your answer above, I just changed all my scripts (about a dozen of them). In the process, I found some cases where I had inkey /c followed by input. I suppose that both inkey /c and input /c do the same thing, but it was sloppy coding.

Thanks, by the way, for all the changes you made in version 34 to address my requests.
 
Doing both will require a major rewrite of INPUT & INKEY.

Why a major rewrite? It would only take 3-4 lines to overload either one with a plugin ... if there's only one arg and it's "/C" EatKeystrokes() and return 0, else return 0xFEDCBA98.
 
Why a major rewrite? It would only take 3-4 lines to overload either one with a plugin ... if there's only one arg and it's "/C" EatKeystrokes() and return 0, else return 0xFEDCBA98.

One of us knows the existing code, and one of us doesn't ...

It's not that simple. Those routines are calling deep into other routines to do the work, and this would require changing the parameters of several functions (which are called a lot of other places). It would be messy, particularly at this late date.
 
One of us knows the existing code, and one of us doesn't ...

It's not that simple. Those routines are calling deep into other routines to do the work, and this would require changing the parameters of several functions (which are called a lot of other places). It would be messy, particularly at this late date.
OK. I figured I was over-simplifying things.
 
The only reason for being able to enter the commands with just the /C option was for backward compatibility.

The way it is now is the right way, so no reason to do a lot of work. It seemed to Vince and me that the coding would be easy enough, but we don't know the code. Also, as I wrote, I've already fixed all of my scripts. If I use them in versions before 34, I'll just have to be careful not to fill the keyboard buffer with any typing while the script is running and before the prompt.
 
I’m actually coming here because I have asked similar questions in the past and hit a wall today.

My pause is an alias that calls a pause-alias.bat that gives me the option of passing a message other than "press any key to continue", which prefixes the message with an emoji, which sets the window title, and which...

DOES NOT....

clear the keyboard buffer prior to the pause. Which means i could accidentally press a key and then an hour later, a pause that i need to happen will not happen because the "any key" was already pressed an hour ago.

Oh i’m trying to clear it. I’ve looked into this many times in the past. But now i’m sitting down and definitively testing this...


1) pause /c doesn’t actually clear it
2) input /c /w0 %%dummyvarname doesn’t actually clear it
3) repeating #2 10 times in advance doesn’t fix it
4) doing #3 and #1 both doesn’t fix it
5) using the pause command directly doesn’t fix it?!?!?!? I really thought it was a BAT file subtlety but the failure of the command line option to work as implied seems to be engrained in the commands themselves, so likely in their interface with windows (????)

It’s simply impossible to clear the buffer...



Step 1: Sleep 2 %+ pause
Step 2: mash keyboard
Step 3: watch pause fail to pause



QED: It’s impossible to reliably pause if you have a cat or child around who may press a key at any point.

Desired behavior: Pause pauses it no matter what happened before the pause command. The "any key" that is pressed only counts keys AFTER pause


In my case, this causes scripts meant to run overnight to end up being randomly paused and to not continue, because in some cases, when the keys are in the buffer, the next line of the script isn’t executed. Instead, the keys hit many minutes (or hours) ago are displayed on the screen until I hit another key and/or enter. It’s been a bit of a mystery that’s halted tons of progress on various projects.

But first, my primary concern is that the command called directly doesn’t work as implied. The buffer isn’t cleared.

I could really use a reliable way to claer the buffer
 
I'm not sure what point you're trying to make here. There is no option in PAUSE to clear the keyboard buffer. This is WAD. PAUSE /C is not an option to clear the buffer; it's an option to clear the line after pressing a key.

There is no "SLEEP" command in TCC. Did you mean to say DELAY?

If you need to clear the buffer, you can use INKEY or INPUT instead. They definitely do clear the keyboard buffer.
 
Sleep is actually a bat for me that works very much like delay. (but the cursor goes to a random color & shape every second so it doesn’t feel hang-y) ..... Oops!
 
It does here in v34. It does not in v33.
Love to hear that! "Do nothing and it will fix itself".

But I updated my pause-alias.bat to use inkey /c instead of input /c! That subtle difference gets my brain every time.

Thank you!!
 
Back
Top