cmd typing effect?

Status
Not open for further replies.
is it possible to echo across a line? so you can have a sort of typing effect? like it shows the first letter then the cursor then the next letter:
H_>HE_>HEL_>HELL_>HELLO_?
I want to make a batch file with a typing effect in it.

Thanks in advance
 
Well, you could do it this way....


@Echo off
title Typewriter effect :)
echo H
ping 0.0.0.0 -n 1.5 > NUL
cls
echo He
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hel
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hell
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello?
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? A
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? An
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? Any
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? Anyo
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? Anyon
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? Anyone
ping 0.0.0.0 -n 1.5 > NUL
cls
echo Hello? Anyone?
pause >nul



Im sure there are better ways, but this is all i know.
 
Well, here's an approach:

This one is executable. You launch it and then it asks you to input a string.
(Credit to jeb at stackoverflow for the character counter part.)

Code:
@echo off
setlocal EnableDelayedExpansion
for /f %%c in ('copy /Z "%~f0" nul') do set "BK=%%c"
set /p line=Type a sentence: 


call :length result line
:length charcount line
(   
    set "s=!%~2!#"
    set "len=0"
    for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
        if "!s:~%%P,1!" NEQ "" ( 
            set /a "len+=%%P"
            set "s=!s:~%%P!"
        )
    )
)

set charcount=%len%
set actchars=0
:write
<nul set /p "=!line:~0,%actchars%!!BK!"
ping -n 1 localhost >nul
if %actchars%==%charcount% goto stop
set /a actchars +=1
goto write

:stop
pause>nul
exit /b
 
Last edited:
Status
Not open for further replies.
Back
Top