Sign in to follow this  
Followers 0
element72

Pause in loop function

2 posts in this topic

#1 ·  Posted (edited)

I need a little help understanding what autoit is doing in my script when I have "pause" integrated. The g_bPaused was from the example I got. The g_aPaused was my attempt at creating a pause in my script by pressing the same hotkey again.  My question: will this essentially take up more RAM if I hit the same hotkey non-stop as oppose to pausing with the down arrow key?

Does hitting the down arrow key "pause" the loop function and executes the "togglepause" function? Is that literally happening?

Global $g_bPaused = False
Global $g_aPaused = False
HotKeySet("{UP}", "loop")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{DOWN}", "TogglePause")

While 1
    Sleep(100)
WEnd


Func loop()
    $g_aPaused = Not $g_aPaused
    ToolTip("")
    While $g_aPaused
        Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
        Send("f")
        Local $fDiff = TimerDiff($hTimer)
        ConsoleWrite($fDiff & " miliseconds" & @LF)
    WEnd
    While Not $g_aPaused
            Sleep(100)
        ToolTip('Script is "Paused"', 500, 500)
    WEnd
EndFunc   ;==>loop


Func TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(100)
        ToolTip('Script is "Paused"', 500, 500)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause


Func Terminate()
    Exit
EndFunc   ;==>Terminate
 

Edited by element72

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't understand your question. The TogglePause() example, in the help file, uses the same hotkey to both pause and resume your script. The first loop (outside the function) is interrupted by the hotkey press. Then TogglePause() interrupts itself the next time you press the hotkey (recursion). After interrupting itself, the script returns to the same point (inside the loop) in first instance of TogglePause(), checks the global flag and determines that it is no longer True (because it was switched back on the second call to the same function). When the flag is False, the loop ends, the function terminates and normal operations can resume.

Edited by czardas

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