Sign in to follow this  
Followers 0
Burgaud

Help with TimerInit() and TimerDiff()

4 posts in this topic

$Clock = TimerInit()

; 3.98 seconds later

TimerDiff($Clock) would give me 3980

Is there a way to "Freeze/Pause" $Clock such that TimerDiff() would not increase?

ie

$Clock = TimerInit()

; 2 seconds later

Pause $Clock

;5 seconds later

TimerDiff($Clock) would give me 2000

unpause $Clock

.

.

.

3 seconds later

TimerDiff($Clock) would give me 5000

Is this possible?

Share this post


Link to post
Share on other sites



No.

What do you try to achieve?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If when you 'pause' you start another time, you can do some subtraction and get the time:

HotKeySet("b", "PauseTimer")
HotKeySet("c", "escape")
$bConsoleWrite = False
$PausedCummulative = 0
$bPaused = False
$ThePausedTimer = 0
$TheTimer = TimerInit()
While True

    While $bPaused
        Sleep(100)
        $bConsoleWrite = True
    WEnd

    Sleep(100)
    If $bConsoleWrite Then
        $PausedCummulative+=TimerDiff($ThePausedTimer)
        ConsoleWrite(Round(TimerDiff($TheTimer)/1000,2) & @tab & "-" & Round($PausedCummulative/1000,2) & @tab & "=" & Round((TimerDiff($TheTimer)-$PausedCummulative)/1000,2) & @CRLF )
        $bConsoleWrite = False
    EndIf
WEnd

Func PauseTimer()
    $bPaused = Not $bPaused
    If $bPaused Then
        $ThePausedTimer = TimerInit()
        ConsoleWrite("Initiate paused timer" & @CRLF)
    Else
        ConsoleWrite("End paused timer" & @CRLF)
    EndIf
EndFunc

Func escape()
    Exit
EndFunc

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

also AdlibRegister() may be useful...

#include <GUIConstantsEx.au3>
Global $Paused = True ; True or False
Global $MyTimer = 0 ; Actual timer position

AdlibRegister("MyTimer", 100) ; function fired every 100 ms

$Form1_1 = GUICreate("MyTimer", 120, 70, 100, 100)
$seconds = GUICtrlCreateLabel($MyTimer, 10, 10, 80, 25)

$Toggle_Button = GUICtrlCreateButton("Toggle timer", 10, 40, 100, 20)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Toggle_Button
            ToggleTimer()
    EndSwitch
WEnd

Func MyTimer()
    If Not $Paused Then
        $MyTimer += 0.1
        GUICtrlSetData($seconds, $MyTimer)
    EndIf
EndFunc   ;==>MyTimer

Func ToggleTimer()
    $Paused = Not $Paused
EndFunc   ;==>ToggleTimer
Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
Sign in to follow this  
Followers 0