views:

42

answers:

1
A: 

God bless you my child,

What kind of counter do you use? sleep.exe? [timer.exe][1] ? [sleep.bat][2] ?

And you need to execute this timer in parallel with your key press counter? Is it convenient to you just to compare times.Check here - http://ss64.com/nt/syntax-gettime.html

and based on this:

 @echo off
      call :currenttime
      call :targettime

      set  /A keypress=0
      call :keycsubroutine


      ::::::::::::::::::::::::::::::::::::::::::
      ::
      :keycsubroutine

      :start
      :--> start your counting code

      call :currenttime
      set /A keypress=%keypress%+1
      echo %keypress%
        echo --- %_current_time%
        echo --- %_target_time%
       if %_target_time%  gtr %_current_time% (

         goto :start
       )


      :--> end of kcounting
      goto :EOF
      ::
      :::::::::::::::::::::::::::::::::::::::


      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      ::
      :currenttime
      SETLOCAL
      For /f "tokens=1-3 delims=1234567890 " %%a in ("%time%") Do set "delims=%%a%%b%%c"
      For /f "tokens=1-4 delims=%delims%" %%G in ("%time%") Do (
        Set _hh=%%G
        Set _min=%%H
        Set _ss=%%I
        Set _ms=%%J
      )
      :: Strip any leading spaces
      Set _hh=%_hh: =%

      :: Ensure the hours have a leading zero
      if 1%_hh% LSS 20 Set _hh=0%_hh%

      ::Echo The time is:   %_hh%:%_min%:%_ss%
      ENDLOCAL&Set _current_time=%_hh%%_min%%_ss%
      goto :EOF
      ::
      ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


      :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      ::
      :targettime
      SETLOCAL
      For /f "tokens=1-3 delims=1234567890 " %%a in ("%time%") Do set "delims=%%a%%b%%c"
      For /f "tokens=1-4 delims=%delims%" %%G in ("%time%") Do (
        Set _hh=%%G
        Set _min=%%H
        Set _ss=%%I
        Set _ms=%%J
      )
      :: Strip any leading spaces
      Set _hh=%_hh: =%

      :: Ensure the hours have a leading zero
      if 1%_hh% LSS 20 Set _hh=0%_hh%

      Set /A _target_mins=%_min%+1
      set /A _target_hrs=%_hh%

      if %_target_mins% gtr 60 (
        set _target_mins=00
        set /A _target_hrs=%_hh%+1
      )

      if %_target_hrs% gtr 24 (
            set _target_hrs=00
      )

      ::Echo The time is:   %_hh%:%_min%:%_ss%
      ENDLOCAL&Set _target_time=%_target_hrs%%_target_mins%%_ss%
      goto :EOF
      ::
      :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

I like the idea here :)

I tried switching a global variable before and after, but i can't manage to make it to keep in the main window the last value set in the prompt window

Instead of using flag variable you can use a flag file e.g. %TEMP%\flag with echo. >%TEMP%\flag

and when your timeout expires to delete the file.And in the same time you can use

IF EXIST %TEMP%\flag ( set /a counter=%counter%+1) else (goto :somewhereelse)

in your other script.

Amen.

npocmaka