简体   繁体   中英

Windows 7 command prompt batch onscreen simulated typing

I am currently trying to work on a batch file that opens up a command prompt, once opened the command prompt starts simulating typing, here is what I have so far Coding:

@echo off 
setlocal 
for %%i in (H e l l o  H o w  A r e  y o u) do ( 
    set /p "=%%i"<nul 
    ping 169.254.0.0 -n 1 -w 500 >nul 
) 
echo; 
goto :EOF

the problem I have is, I can only do one word, when I start the command prompt it starts typing it, like this HelloHowAreYou I need the words to be separated, is there anything I can do? Oh, I'm also on Windows 7

Copy of my example from Gist: https://gist.github.com/davidruhmann/6073962 since OP is unable to access GitHub.com

@echo off
call :Typing "hello world!"
exit /b 0

:: Use a known invalid reserved IP address because it should always timeout.
:: http://en.wikipedia.org/wiki/Reserved_IP_addresses
:: 127.0.0.1 will never timeout and will always return each tick in 1 second.
:Typing <Message>
setlocal
set "Message=%~1"
:TypingLoop
ping 192.0.2.0 -n 1 -w 500 >nul
if "%Message:~1,1%"==" " ( <nul set /p "=%Message:~0,2%" ) else ( <nul set /p "=%Message:~0,1%" )
set "Message=%Message:~1%"
if defined Message goto TypingLoop
endlocal
exit /b 0

This works in Windows-XP:

@echo off 
setlocal 
for %%i in (H e l l o " " H o w " " A r e " " y o u) do ( 
    set /p "=%%~i"<nul 
    ping 169.254.0.0 -n 1 -w 500 >nul 
) 
echo; 
goto :EOF

However, in newer Windows versions the set /P command eliminate leading spaces, so I am not shure if this method works in Windows 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM