Jump to content

End specific function


gumcaj
 Share

Recommended Posts

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.

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

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
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...