3

I just got some code to do this effect, but I need to it to type faster, like a letter every half a second.

for %%i in (h e l l o o o o o o o o o o o o o o) do (
   set /p a=%%i<nul
   ping 0.0.0.0 -n 2.0>nul 2>&1
)

Can someone modify it so it types faster?

3rd Battalion
  • 25
  • 1
  • 7
Giuseppe Lolli
  • 167
  • 4
  • 15
  • Use the ping timeout parameter `-w`. Example: `ping 10.1.1.1 -n 1 -w 500 >nul` Full Typing Example: https://gist.github.com/davidruhmann/6073962 – David Ruhmann Feb 06 '15 at 15:57
  • You can try adding the wait parameter (`ping 0.0.0.0 -n 2 -w 500>nul 2>&1`). The time is in milliseconds (1 second is 1000 ms), so 500 would be 0.5 seconds. – Ken White Feb 06 '15 at 15:58
  • @KenWhite `0.0.0.0` won't work. It has to be an IP that results in "Request timed out." errors. @David I suggest that `169.254.0.0` would be a worthwhile IP to use generically, as `10.x`, `192.168.x` and `172.16-31.x` could potentially not be as bogus as one would wish. – rojo Feb 06 '15 at 18:48
  • @rojo: I took the existing command from the question and added a parameter to it. If you have an issue with the address used, discuss it with the question poster. :-) – Ken White Feb 06 '15 at 20:12

5 Answers5

6

The ping solution in the comments above is a worthwhile solution for computers with installed network interfaces (as almost all have).

@echo off
setlocal

for %%i in (h e l l o o o o o o o o o o o o o o) do (
   set /p "=%%i"<nul
   ping 169.254.0.0 -n 1 -w 500 >nul
)
echo;
goto :EOF

However, it appears that the minimum wait time recognized with this method is 500ms. If you change the 500 to a lower value, you still pause a half second between letters. If you want finer control, or if your computer has no network interface, you'll have to borrow from another runtime environment -- JScript, for example.

@if (@CodeSection == @Batch) @then

@echo off
setlocal

for %%i in (h e l l o o o o o o o o o o o o o o) do (
   set /p "=%%i"<nul
   cscript /nologo /e:JScript "%~f0"
)
echo;

goto :EOF
rem // end batch portion

@end
// begin JScript chimera
WSH.Sleep(Math.random() * 250 + 100);

Note on the choice of IP to ping: For the -w switch to work as intended, the IP you ping must result in "Request timed out". You can use a non-existent LAN IP such as a 10.x.x.x or 192.168.x.x. But for widespread deployment, if you can't be certain that those ranges are unused, a link local IP in the range of 169.254 should work just fine for this purpose. Please do not use an IP in historical bogon space like 1.1.1.1 or 1.2.3.4. Just because such addresses don't reply doesn't mean your packets aren't adding to network congestion somewhere.

Eventually as IPv4 addresses draw ever nearer to complete exhaustion, people need to be more conscientious of polluting the Internet with bogus traffic. It could be that 1.1.1.1 and 1.2.3.4 will never be useful to anyone because they are so often abused by casual scripters. But that's no reason to add to the mistreatment of those addresses. See this page for further reading, and please, save the bogons.


Jack.bat

Just to see how far I could take the typewriter effect, I wrote a script that outputs text similar to the X screensaver "Jack". It outputs the same line over and over, and randomly introduces typographical errors. Run it and you'll be mesmerized, rooting for the script to complete a line without any typos.

@if (@CodeSection == @Batch) @then

@echo off
setlocal

cls
color 70

call :split chars "All work and no play makes Jack a dull boy."

:begin
for %%i in (%chars%) do call :type "%%~i"
echo;
goto begin

:split <var_to_set> <str>
setlocal enabledelayedexpansion
set "line="
set "str=%~2"
for /L %%I in (0,1,43) do set line=!line! "!str:~%%I,1!"
endlocal & set %~1=%line%
goto :EOF

:type <char>
cscript /nologo /e:JScript "%~f0" "%~1"
goto :EOF

@end
// end batch / begin JScript chimera
function pause() { WSH.Sleep(Math.random() * 250 + 100); }
function odds(num) { return !(Math.round(Math.random() * num) % num) }
function backspace() { WSH.StdOut.Write(String.fromCharCode(8)); }

pause();

if (odds(15)) {
    WSH.StdOut.Write(String.fromCharCode(Math.round(Math.random() * 95 + 32)));
    pause();
    if (!odds(20)) {
        backspace();
        pause();
    }
}

if (odds(300)) WSH.Echo('');
if (!odds(400)) WSH.StdOut.Write(WSH.Arguments(0));
Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
  • 1
    "bogon" is such a great term—I've actually never heard it before. Bogon space is a crucial nonrenewable resource. – meatspace Feb 06 '15 at 19:42
4

Just give a try for this code : Message Typewriter + Speaking Voice

@echo off
Title Typewriter with speaking voice by Hackoo 2016
Color 0A & Mode con cols=70 lines=3
set Msg="This is only a testing string to see if my script really works or not?"
Call :Typewriter %Msg%
set Msg="              What are you doing now dude ?"
Call :Typewriter %Msg%
set Msg="         I want to say Hello for everybody on StackOverflow !"
Call :Typewriter %Msg%
pause>nul
Exit /b
::*********************************************************************
:TypeWriter
Cls
echo(
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 150
echo For x = 1 to intTextLen
echo     strTempText = Mid(strText,x,1^)
echo     WScript.StdOut.Write strTempText
echo     WScript.Sleep intPause
echo Next
echo Set Voice=CreateObject("SAPI.SpVoice"^)
echo voice.speak strText
)>%tmp%\%~n0.vbs
@cScript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1"
exit /b
::********************************************************************* 
Hackoo
  • 18,337
  • 3
  • 40
  • 70
2
@echo off
setlocal enableextensions enabledelayedexpansion

set lines=1


set "line1=Check it out M8! Im typing but not typing! BEWM! BEWM! BEWM!"


for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type

pause>nul
goto :EOF

:type
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

:: adjust the 3 in the line below: higher is faster typing speed

for /L %%b in (1,3,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto :type
J03L
  • 314
  • 3
  • 17
1

Pinging 0.0.0.0 gives PING: transmit failed. General failure error message nearly immediately.

(Edited according to suggestive rojo's comment)

Better to ping some address returning Request timed out message chosen from a Private-Use Network range.

for %%i in (h e l l o o o o o o o o o o o o o o) do (
   set /p a=%%i<nul
   ping a.b.c.d -4 -n 1 -w 500>nul 2>&1
)

Here:

  • a.b.c.d = address returning Request timed out message, see (*) below.

  • -4 = force using IPv4.

  • -n 1 = number of echo requests to send (one).

  • -w 500 = timeout in milliseconds to wait for each reply (500=1/2 sec); this should work to cca 5 seconds (approximate time for one unsuccesfull echo request).

(*) The following IPv4 address ranges have been reserved by the IANA for private internets, and are not publicly routable on the global internet:

 10.0.0.0     --   10.255.255.255  (10/8       prefix)
 172.16.0.0   --   172.31.255.255  (172.16/12  prefix)
 192.168.0.0  --   192.168.255.255 (192.168/16 prefix)
Community
  • 1
  • 1
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • Nooo, `1.1.1.1` is not a good IP to use! It's not in a reserved range, and polluting it causes more harm than good. [See this article](https://labs.ripe.net/Members/franz/content-pollution-18) and [this one](http://packetlife.net/blog/2010/feb/5/ripe-plays-with-1-0-0-0-network-apnic-allocation/). Please modify your answer. Use `169.254` or some other range. – rojo Feb 06 '15 at 19:09
0
@echo off
mode con:cols=80 lines=25
rem CenterSelf
set FGcol=10
rem ChangeColor %FGcol% 0
rem PrintBoxAt 12 31 3 20 2
rem ChangeColor 0 %FGcol%

rem Wait 30
REM COPY FILES HERE

rem ShadeBoxAt 13 32 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 34 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 36 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 38 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 40 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 42 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 44 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 46 1 2 2

rem Wait 30
REM COPY MORE FILES HERE

rem ShadeBoxAt 13 48 1 2 2

rem ClearColor
rem Locate 25 1
pause
Ihor Konovalenko
  • 1,298
  • 2
  • 16
  • 21
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 05 '21 at 11:31