Link to home
Start Free TrialLog in
Avatar of Armitage318
Armitage318

asked on

Simulate keypress in batch script

Hi,
I need to use a command line tool to do some migration. This tool (an exe file) prompts "press any key to continue" before exit.
My goal is to create a batch script to do several migrations, one at a time, but at this stage it is unuseful because I need to press a key after each migration.
How can I "simulate" key pressing?
OS: Windows 10.
Thank you
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need a tool like this.  An automation general scripting software.

https://www.autoitscript.com/site/

It allows you to intercept an open window and take action based on what is happening inside the window.

You need to know how to do basic programming.  But if you know how to do a batch file it should be fairly easy for you to learn.
I suggest to go with the VB script with the SendKeys function.
Refer this link for the parameters.
https://www.vbsedit.com/html/4b032417-ebda-4d30-88a4-2b56c24affdd.asp
Avatar of Armitage318
Armitage318

ASKER

Hi Qlemo,
your solutions are ok, I just get this error in prompt window:

Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read

is there a way to "suppress" this message?
I would prefer not using additional software to achieve this, if possible
Thank you
If you get a prompt window, no. But you can look if the exe has a commandline switch to do things silently - something like /q (quiet) or /silent or /noprompt.
Note - the SendKeys approach would prevent that prompt, and repeatedly have to send a key to the command window instead - difficulty here is to detect at which time the exe is prompting. It is possible, but requires a lot of fiddling and try-and-error.

AutoHotKey and similar solutions would be able to detect the "press any key" prompt and act on it.