Jump to content
boat_58

Script Timer Tracking Help

Recommended Posts

I want to implement a timer on a script i am creating to monitor how long the script running for. I pulled the timer script posted in another post to get started but i am still not figuring out how to implement the timer and the script together so that it counts smoothly when the script is running. Right now, the timer just counts when it loops back to it every 10 second. Can anyone help please?

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet('{ESC}', 'Stop')
HotKeySet('{SPACE}', 'Pause')
Global $Paused

;;Create the GUI window
GUICreate("Timer", 200, 25, 3, 800, -1, $WS_EX_TOPMOST)

;---------------------------- Timer GUI ------------------------------
;Label for the time
GUICtrlCreateLabel("Script Time:", 5, 5)
;Place to display the time
$TimerTime = GUICtrlCreateLabel("", 150, 5, 100, 25)
;Create the timer
$Timer = TimerInit()

;Time globals
$CurSec = 0
$CurMin = 0
$CurHr = 0

;Start showing the window
GUISetState(@SW_SHOW)

For $a = 1 To 1000
;---------------------------- Main Loop ------------------------------
While Not(GUIGetMsg()==-3)
    Sleep(2)
    ;Update the Timer time
    If Not(GUICtrlRead($TimerTime)==TimerGetStringTime($Timer)) Then
        GUICtrlSetData($TimerTime,TimerGetStringTime($Timer))
    EndIf
    
    ;Activity Clicks
    MouseClick("left", 914, 821)      ;(1)
    Sleep(1000)     ; Pause for 1 second
    MouseClick("left", 961, 608)     ;
    Sleep(1000)     ; Pause for 1 second
    MouseClick("left", 796, 408)     ;(2)
    Sleep(1000)     ; Pause for 1 seconds
    MouseClick("left", 945, 408)     ;(3) 
    Sleep(1000)     ; Pause for 1 second
    MouseClick("left", 1109, 408)     ;(4)
    Sleep(1000)     ; Pause for 1 second
    MouseClick("left", 830, 624)     ;(5)
    Sleep(1000)     ; Pause for 1 second
    MouseClick("left", 1114, 581)     ;(6)
    Sleep(1000)     ; Pause for 1 second
WEnd
Next


;Pause Function
Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>Pause

;Stop Function
Func Stop()
    Exit
EndFunc   ;==>Stop

;--------------------- Timer Support Functions ----------------------
;Note: All of these functions could be condensed into the TimerGetStringTime function, but they are expanded for your benefit
Func TimerGetStringTime($hTimer)
    ;Fix timer flicker
    $Sec = TimerGetSec($hTimer)
    $Min = TimerGetMin($hTimer)
    $Hr = TimerGetHrs($hTimer)
    If $CurSec < $Sec Or $CurSec - $Sec > 50 Then $CurSec = $Sec
    If $CurMin < $Min Or $CurMin - $Min > 50 Then $CurMin = $Min
    If $CurHr < $Hr Or $CurHr - $Hr > 50 Then $CurHr = $Hr
    ;Return the time
    Return String($CurHr) & ":" & String($CurMin) & ":" & String($CurSec)
EndFunc   ;==>TimerGetStringTime
Func TimerGetSec($hTimer)
    $Time = TimerDiff($Timer)   ;Get the time from the timer
    $Time = Int($Time / 1000)   ;Convert milliseconds to secconds
    $Time = Mod($Time, 60)      ;Remove all secconds past 60
    Return $Time                ;Return the Value
EndFunc   ;==>TimerGetSec
Func TimerGetMin($hTimer)
    $Time = TimerDiff($Timer)   ;Get the time from the timer
    $Time = Int($Time / 60000)  ;Convert milliseconds to minutes
    $Time = Mod($Time, 60)      ;Remove all Minutes past 60
    Return $Time                ;Return the Value
EndFunc   ;==>TimerGetMin
Func TimerGetHrs($hTimer)
    $Time = TimerDiff($Timer)   ;Get the time from the timer
    $Time = Int($Time / 3600000) ;Convert milliseconds to hours
    $Time = Mod($Time, 24)      ;Remove all Minutes past 24
    Return $Time                ;Return the Value
EndFunc   ;==>TimerGetHrs

 

Share this post


Link to post
Share on other sites

How about a simplified example that measures the time from when you start until when you close the GUI, does this help?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Timers.au3> ; used to control timer functions

$Form1 = GUICreate("Time Tester", 400, 206, 407, 355)
$Button1 = GUICtrlCreateButton("Close Me!", 128, 64, 121, 41)
GUISetState(@SW_SHOW)

$Timer = TimerInit(); start the timer

 While 1
        Switch GUIGetMsg()
            case $Button1
                MsgBox(0,'',round((_Timer_Diff($Timer)/1000),2)) ; displays time script ran in seconds rounded to two digits.
                exit
            Case $GUI_EVENT_CLOSE ; listens for when you close the GUI
                MsgBox(0,'',round((_Timer_Diff($Timer)/1000),2)) ; displays time script ran in seconds rounded to two digits
                exit
        EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...