Need help about time condition on stopwatch Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
skeptical

Need help about time condition on stopwatch  Topic is solved

18 Sep 2017, 17:55

Hi i need some advice about stopwatch code
this code is work perfectly for me but i need to improve something
first i need to turn text color to red when time is => 10 sec
and i need the code to ignore reset command from {f1} if time is <10 sec

can someone help me please ?

Code: Select all

; http://www.autohotke...ple-stop-watch/

#SingleInstance FORCE

#NoEnv
SetBatchLines, -1
; Some variables
ElapsedTime := A_YYYY                                 ; initialize ElapsedTime, it will be treated as YYYY0101000000
BalanceTime := 0                                      ; initialize BalanceTime (time not counted yet)
; Tray menu
Menu, Tray, NoStandard                                ; clear the tray menu for customizing
Menu, Tray, Add, Quit, AppExit                        ; add item "Quit" to call AppExit
Menu, Tray, Default, Quit                             ; double-click on the tray icon will call "Quit"
Menu, Tray, Tip, % " AHK short-time Stopwatch "       ; add a nice tool tip
; GUI
Gui, +LastFound ; Added
WinSet, TransColor, FFFFFF 100 ; Added
;
Gui, +ToolWindow -Caption +AlwaysOnTop                ; made some changes for relative positioning and sizing
Gui, Margin, 0, 0                                     ; http://l.autohotkey....ui.htm#Position
Gui, Font, S32 CDefault Bold, Verdana
Gui, Add, Text, Center vDisplayTime, 00:00
Gui, Font, S12, Verdana
Gui, Add, Button, x+0 yp w1 h1 vBtnStartStop gStartStop Default, Start`nStop
Gui, Add, Button, x+0 yp w1 h1 vBtnReset gReset, Reset

Gui, Show, , Stop Watch

if (A_TickCount - StartTime = 20000 )
{
    MsgBox Too much time has passed.
}

f1::
gosub, Reset
Gosub, StartStop
return

Return
; Exit label
AppExit:
ExitApp
; BtnStartStop label
StartStop:
   GuiControlGet, BtnStartStop                        ; get the caption of the button
   If (BtnStartStop = "Start`nStop") {                ; if it is "Start`nStop"
      StartTickCount := A_TickCount - BalanceTime     ; initialize StartTickCount
      SetTimer, StopWatch, 10                         ; start the timer called every 10 ms to be accurate
      GuiControl, , BtnStartStop, Stop                ; set the caption to Stop
   } Else {                                           ; it should be "Stop"
      BalanceTime := A_TickCount - StartTickCount     ; memorize the balance time not counted yet
      SetTimer, StopWatch, Off                        ; stop the timer
      GuiControl, , BtnStartStop, Start`nStop         ; set the caption to "Start`nStop"
   }
Return
; BtnReset label
Reset:
   SetTimer, StopWatch, Off                           ; stop the timer
   GuiControl, , BtnStartStop, Start`nStop            ; set the caption of BtnStartStop to "Start`nStop"
   GuiControl, , DisplayTime, 00:00                   ; initialize DisplayTime
   ElapsedTime := A_YYYY                              ; initialize ElapsedTime, it will be treated as YYYY0101000000
   BalanceTime := 0                                   ; initialize BalanceTime
   GuiControl, Focus, BtnStartStop                    ; set the focus on BtnStartStop
   GuiControl, -Default, BtnReset                     ; remove the BS_DEFPUSHBUTTON (default) style
   GuiControl, +Default, BtnStartStop                 ; set the BS_DEFPUSHBUTTON (default) style
Return
; Timer routine
StopWatch:
   If ((A_TickCount - StartTickCount) >= 1000) {      ; if current tickcount - StartTickCount >= 1000 (i.e. 1 second)
      StartTickCount += 1000                          ; add 1000 ms (1 second) to StartTickCount
      ElapsedTime += 1, S                             ; add 1 second to ElapsedTime
      FormatTime, DisplayTime, %ElapsedTime%, mm:ss   ; format ElapsedTime to mm:ss
      GuiControl, , DisplayTime, %DisplayTime%        ; update DisplayTime
   }
Return

^#!x::ExitApp
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Need help about time condition on stopwatch

19 Sep 2017, 04:32

GuiControl, Font: Changes the control's font to the typeface, size, color, and style currently in effect for its window. For example: ...
skeptical

Re: Need help about time condition on stopwatch

19 Sep 2017, 17:12

BoBo wrote:
GuiControl, Font: Changes the control's font to the typeface, size, color, and style currently in effect for its window. For example: ...
Hi thank for reply
my problem is time condition, i totally have no idea what code i need to use
i try to use

Code: Select all

Stopwatch:
timers += 1
if(timers > 10)
and

Code: Select all

  If ((A_TickCount - StartTickCount) < 10000) 
  
but its doesnt seem to work

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, ht55cd3, Joey5, mamo691, sebalotek and 368 guests