This takes advantage of Command Prompt's input buffer. You might notice you can press keys while a batch process is running, and they will be placed in the input of the following set /p. So, this inputs 80 space characters (the default max width of a single line in Command Prompt) to scroll the window to the next line, then clears it with the escape key.
Why not do this just before set /p is executed? Because the window requires focus for WshShell's SendKeys method, and using the AppActivate method is intrusive and more prone to error.
Edit: I realized, at expected focus times the window might not have focus for any particular reason, as the Windows OS allows things to start without focus. So, AppActivate works well under these circumstances. It also prevents missed SendKeys if you press enter after input, and click away from the window really fast.
space.vbs (edit added a.appactivate wscript.arguments(0))
Code: Select all
set a=wscript.createobject("wscript.shell")
a.appactivate wscript.arguments(0)
a.sendkeys " {esc}"
Example batch: (edit added title stuff and "%title%" argument)
Code: Select all
@rem Initialization. Start the batch off with the key presses, while the window has focus.
@echo off
set title=Unique Window Name
title %title%
cscript space.vbs //nologo "%title%"
:: Get the Command Prompt scrolling.
for /l %%x in (1,1,25) do echo:
:: Do a delay as if we are processing something.
ping 0 -n 3 >nul
:: Asking for user input. See, did it work?
set /p "var=Input: "
:: Must immediately follow set /p, for the next set /p encountered.
cscript space.vbs //nologo "%title%"
:: Let's delay again, as if we are processing something.
ping 0 -n 3 >nul
:: Asking for user input again. You can see how this continues to work...
set /p "var=Input: "
:: Following again.
cscript space.vbs //nologo "%title%"
:: But, it could override pause. Read below.
pause
exit
While in my tests I had no problem with running the cscript immediately before a pause command, it's possible the keys may override the pause. To be totally safe, you need to remove the last cscripts before any pauses. This shouldn't be a problem though, because pause ignores the input buffer, and Command Prompt doesn't proceed until the Windows scripting host closes, having sent all key presses.