Discussion:
Simulating a key input to an external command
(too old to reply)
Tom Del Rosso
2024-05-12 22:20:37 UTC
Permalink
Is there a way to give an *external* command "any key" input without
using a macro utility?

Years ago there was some mention of using START /B but I can't find an
example. The experiment below is just confusing with the sequence of
output and input all mixed up, but both PAUSE commands still need input.

And what's needed is to give input to an external command. Piping echo
doesn't always work.


@echo off
echo TOP OF FILE

if "%~1"=="JUMP" goto :%2

echo FIRST RUN

START "SUBC" /B "%~0" JUMP SUBC

echo 1
pause
echo 2
exit

:SUBC
echo 3
pause
echo 4
exit
Kenny McCormack
2024-05-12 22:32:46 UTC
Permalink
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
What is a "macro utility"? And why don't you want to use one, whatever it is?
--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...
Tom Del Rosso
2024-05-12 22:44:24 UTC
Permalink
Post by Kenny McCormack
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
What is a "macro utility"? And why don't you want to use one,
whatever it is?
A utility that simulates input from keyboard and mouse, like AutoIt,
AutoHoykey, MiniMouseMacro, et al. It's just cumbersome when all you
need is automated input to a "press any key" prompt.
--
Defund the Thought Police
JJ
2024-05-13 03:22:34 UTC
Permalink
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
Years ago there was some mention of using START /B but I can't find an
example. The experiment below is just confusing with the sequence of
output and input all mixed up, but both PAUSE commands still need input.
And what's needed is to give input to an external command. Piping echo
doesn't always work.
@echo off
echo TOP OF FILE
if "%~1"=="JUMP" goto :%2
echo FIRST RUN
START "SUBC" /B "%~0" JUMP SUBC
echo 1
pause
echo 2
exit
:SUBC
echo 3
pause
echo 4
exit
You can borrow Windows Script Host via VBScript to generate keypresses using
`WScript.Shell` object's `SendKeys` function.

https://ss64.com/vb/sendkeys.html

e.g. send ALT+ENTER sychronously:

@echo off
setlocal
Post by Tom Del Rosso
"%temp%\sendkeys.vbs" echo createobject("wscript.shell").sendkeys(wsh.arguments(0))
cscript.exe //nologo "%temp%\sendkeys.vbs" "%{enter}"

e.g. send text asynchronously:

@echo off
setlocal
Post by Tom Del Rosso
"%temp%\sendkeys.vbs" echo createobject("wscript.shell").sendkeys(wsh.arguments(0))
start /b cscript.exe //nologo "%temp%\sendkeys.vbs" "my input{enter}"
set /p "inp=enter input: "
echo input=%inp%
JJ
2024-05-13 03:29:29 UTC
Permalink
Post by JJ
cscript.exe //nologo "%temp%\sendkeys.vbs" "%{enter}"
Whoops. The percent symbol in "%{enter}" should be escaped. i.e. to
"%%{enter}"

Also, the full description for `SendKeys` can be found below.
(long URL warning)

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement
Kenny McCormack
2024-05-13 06:33:50 UTC
Permalink
Post by JJ
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
...
Post by JJ
You can borrow Windows Script Host via VBScript to generate keypresses using
`WScript.Shell` object's `SendKeys` function.
Isn't that pretty much using a "macro utility"?
--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Snicker
JJ
2024-05-13 18:02:48 UTC
Permalink
Post by Kenny McCormack
Post by JJ
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
....
Post by JJ
You can borrow Windows Script Host via VBScript to generate keypresses using
`WScript.Shell` object's `SendKeys` function.
Isn't that pretty much using a "macro utility"?
Oh. You're right. I overlooked that point.

Well, anything other than redirected standard input, would be a macro
utility.
Kenny McCormack
2024-05-13 18:14:46 UTC
Permalink
Post by JJ
Post by Kenny McCormack
Post by JJ
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
....
Post by JJ
You can borrow Windows Script Host via VBScript to generate keypresses using
`WScript.Shell` object's `SendKeys` function.
Isn't that pretty much using a "macro utility"?
Oh. You're right. I overlooked that point.
Well, anything other than redirected standard input, would be a macro
utility.
Yup.

I think the answer to OP's question is: No.
--
Alice was something of a handful to her father, Theodore Roosevelt. He was
once asked by a visiting dignitary about parenting his spitfire of a daughter
and he replied, "I can be President of the United States, or I can control
Alice. I cannot possibly do both."
Tom Del Rosso
2024-05-16 20:36:31 UTC
Permalink
Post by Kenny McCormack
Post by JJ
Post by Tom Del Rosso
Is there a way to give an *external* command "any key" input without
using a macro utility?
...
Post by JJ
You can borrow Windows Script Host via VBScript to generate
keypresses using `WScript.Shell` object's `SendKeys` function.
Isn't that pretty much using a "macro utility"?
No, it's native to Windows.
--
Defund the Thought Police
Tom Del Rosso
2024-05-16 20:37:16 UTC
Permalink
Post by JJ
You can borrow Windows Script Host via VBScript to generate
keypresses using `WScript.Shell` object's `SendKeys` function.
https://ss64.com/vb/sendkeys.html
@echo off
setlocal
Post by Tom Del Rosso
"%temp%\sendkeys.vbs" echo
createobject("wscript.shell").sendkeys(wsh.arguments(0))
cscript.exe //nologo "%temp%\sendkeys.vbs" "%{enter}"
@echo off
setlocal
Post by Tom Del Rosso
"%temp%\sendkeys.vbs" echo
createobject("wscript.shell").sendkeys(wsh.arguments(0))
start /b cscript.exe //nologo "%temp%\sendkeys.vbs" "my input{enter}"
set /p "inp=enter input: "
echo input=%inp%
Thank you!
--
Defund the Thought Police
Loading...