Sign in to follow this  
Followers 0
gumcaj

End specific function

3 posts in this topic

Hi, is it possible to abort/cancel specific function which is currently running?

Let's say I ran function called "Dance"

and then after I pressed a hotkey, the Dance function stopped working.

Is it possible?

Something like " EndFunc "Dance" "

Regards.

Share this post


Link to post
Share on other sites



Hi and Welcome to the forums!

You need to use a variable as a flag that the hotkey sets, and that the Dance checks for (and Return if it's set). Example:

#include <GUIConstantsEx.au3>
 
Global $iFlag = 0
 
GUICreate("SomeTitle", 256, 256)
$hButton = GUICtrlCreateButton("Press me!", 50, 50, 100, 50)
GUISetState()
 
HotKeySet("O", "_Interrupt")
 
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            _Dance()
            ToolTip("")
    EndSwitch
WEnd
 
Func _Interrupt()
    $iFlag = 1
EndFunc
 
Func _Dance()
    For $iX = 1 To 1000
        If $iFlag = 1 Then
            $iFlag = 0
            Return
        EndIf
        ToolTip($iX)
        Sleep(10)
    Next
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

yes, its very simple

; setup your hotkey
HotKeySet("{END}", "MyFunctionOnOFF")
 
; declare global variable for function state
Global $bMyFunction = 0
 
; main script loop
While 1
     MyFunction()
     Otherfunction()
     AndAnotherOne()
Wend
 
; then write a function like this
Func MyFunction()
     If $bMyFunction Then
          ; here goes the rest of your function code ...
     Endif
Endfunc
 
; MyFunction switch
Func MyFunctionOnOFF()
     $bMyFunction = NOT $bMyFunction
Endfunc
Edited by DesireDenied

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