Windows 7命令提示符批量屏幕模拟键入

时间:2015-03-02 17:42:57

标签: windows batch-file command-prompt

我目前正在尝试打开一个打开命令提示符的批处理文件,一旦打开命令提示符开始模拟打字,这是我到目前为止所拥有的 编码:

@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

我遇到的问题是,我只能做一个字,当我启动命令提示符时它开始输入它,就像这个HelloHowAreYou 我需要分开的话,有什么我可以做的吗? 哦,我也在Windows 7上

2 个答案:

答案 0 :(得分:0)

我的示例来自Gist:https://gist.github.com/davidruhmann/6073962,因为OP无法访问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

答案 1 :(得分:0)

这适用于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

但是,在较新的Windows版本中,set /P命令会消除前导空格,因此如果此方法适用于Windows 7,我并不感到舒服。