You are not logged in.

#1 11 Jul 2015 20:41

vendor
Member
Registered: 13 Apr 2014
Posts: 5

help timer

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  sad

Offline

#2 11 Jul 2015 21:18

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: help timer

"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

#3 12 Jul 2015 09:46

vendor
Member
Registered: 13 Apr 2014
Posts: 5

Re: help timer

bluesxman wrote:

"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  smile


my last question
what is the meaning of the code ÷ ?

Offline

#4 12 Jul 2015 13:33

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: help timer

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

#5 13 Jul 2015 12:02

vendor
Member
Registered: 13 Apr 2014
Posts: 5

Re: help timer

Shadow Thief wrote:

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  smile


Thanks in Advance

Offline

Board footer

Powered by