You are not logged in.
Pages: 1
Hi,
i want create some stopwatch in batch, any possible to make it?
@echo off
color f0
:: minute
set menit=0
:: hours
set jam=0
:: sec
set detik=0
:start
echo PRESS H TO START
choice /c h /n
if errorlevel 1 goto stopwatch
goto start
:stopwatch
cls
for /L %%a in (1 1 60) do (
if "%1" equ "1" goto stop
echo %jam%:%menit%:%%a
ping localhost -n 2 >nul
cls
)
set /a menit=%menit%+1
if %menit% equ 60 (
set /a jam=%jam%+1
set menit=0
goto stopwatch_2
)
goto stopwatch_2
:stopwatch_2
for /l %%a in (1 1 60) do (
echo %jam%:%menit%:%%a
ping localhost -n 2 >nul
cls
)
set /a menit=%menit%+1
if %menit% equ 60 (
set /a jam=%jam%+1
set menit=0
goto stopwatch
set
)
goto stopwatch
:stop
pause>nul
sadly, my code just like a regular timer, i hope it could be added stop function
Offline
"choice" has a timeout function
You could replace your "ping localhost" with this:
choice /c ÷s /d ÷ /t 1 /n >nul
if errorlevel 2 goto :stop
The default key-press can be anything, really, but I selected something that doesn't usually appear on a keyboard to prevent accidental key-presses.
Last edited by bluesxman (11 Jul 2015 21:19)
cmd | *sh | ruby | chef
Offline
"choice" has a timeout function
You could replace your "ping localhost" with this:choice /c ÷s /d ÷ /t 1 /n >nul if errorlevel 2 goto :stop
The default key-press can be anything, really, but I selected something that doesn't usually appear on a keyboard to prevent accidental key-presses.
wow it really functions
Thank You very much sir
my last question
what is the meaning of the code ÷ ?
Offline
It's literally the ÷ character. The choice command allows the user to either press ÷ or s, with ÷ being the default key (after 1 second, choice just pretends that the user pressed that key). He chose the ÷ key because it doesn't appear on the keyboard so the user won't press it by accident.
Offline
It's literally the ÷ character. The choice command allows the user to either press ÷ or s, with ÷ being the default key (after 1 second, choice just pretends that the user pressed that key). He chose the ÷ key because it doesn't appear on the keyboard so the user won't press it by accident.
ahh i get it
Thanks in Advance
Offline
Pages: 1