Jump to content

Help with TimerInit() and TimerDiff()


Recommended Posts

$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?

Link to comment
Share on other sites

No.

What do you try to achieve?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.
Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...