Human.bat
Human.bat

Reputation: 145

Auto typing program skips spaces

I made a simple little program in batch that types out character by character the contents of the "_text" variable:

@echo off
SET _start=-1
SET _length=1
SET _text=This is an automated typing machine.

:loop
SET /a "_start=_start+1"
CALL SET _substring=%%_text:~%_start%,1%%
<nul set /p =%_substring%
ping -n 1 -w 1.1.1.1 > nul
goto :loop

However, if you run the program, you can see that any spaces in the "_text" variable was skipped. How can I fix this?

Upvotes: 0

Views: 40

Answers (1)

Dennis van Gils
Dennis van Gils

Reputation: 3462

You can do something like this:

@echo off
setlocal EnableDelayedExpansion
SET _start=-1
SET _length=1
SET "_text=This is an automated typing machine."

:loop
SET /a "_start=_start+1"
CALL SET "_substring=%%_text:~%_start%,1%%"
if "%_substring%"=="" goto end
<nul set /p "=.[bs]%_substring%"
ping -n 1 -w 1.1.1.1 > nul
goto :loop
:end
echo.
pause

However, instead of the [bs], you should put the backspace character, copied from this text-file, as discussed in this answer.

Upvotes: 2

Related Questions