Jump to content

Search the Community

Showing results for tags 'interrupt function'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 2 results

  1. Hello, I am trying to learn how this works. I want to be able to interrupt a running function with winwait.. In this example I want to start notepad and than the script needs to winwait for a specific window. But if that window does not appear then I want the user to be able to interrupt the function and start the next function (run nextprogram.exe") I found some examples and mentioned winwait, but I still could not make it work. I tried to adjust the tutorial https://www.autoitscript.com/wiki/Interrupting_a_running_function , but could not get this working either with a winwait I hope someone can put me in the right direction. Code below is just one of my many attempts... #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ;AutoIt3Wrapper_Run_Debug_Mode=Y ; Set a HotKey HotKeySet("x", "_Interrupt") ; Declare a flag $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) ; Create a dummy control for the Accelerator to action when pressed $hAccelInterupt = GUICtrlCreateDummy() ; Set an Accelerator key to action the dummy control Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) GUISetState() ; Intercept Windows command messages with out own handler GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() _Func_3() Case $hButton_2 _Func_2() EndSwitch WEnd ; Use a wrapper function in place of the blocking function Func _Func_1() ; Make sure the flag is cleared $fInterrupt = 0 ;For $i = 1 To 20 run ("notepad") ConsoleWrite("-Func 1 Running" & @CRLF) ; Run a modified Sleep function which checks for the interrupt ;if _Interrupt_Sleep(1000) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if _Interrupt_Sleep(999999999999999999999999999999999) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) ; Next ConsoleWrite(">Func 1 Ended" & @CRLF) EndFunc ;==>_Func_1 ; And here is the wrapper function itself Func _Interrupt_Sleep($iDelay) ; Get a timestamp Local $iBegin = TimerInit() ; And run a tight loop Do ; Use a minimum Sleep (could also be a WinWaitActive with a short timeout) ;Sleep(10) winwait("sdfdf","sdfsdf") ;<<<<<<----- the winwait for a window I want to skip ; Look for the interrrupt If $fInterrupt Then ; And return True immediately if set Return True EndIf Until TimerDiff($iBegin) > $iDelay ; Return False if timed out and no interrupt was set Return False EndFunc ;==>_Interrupt_Sleep Func _Func_2() ;For $i = 1 To 3 processclose("notepad.exe") ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) ;Next ConsoleWrite(">Notepad killed!" & @CRLF) EndFunc Func _Func_3() run("nextprogam.exe") Endfunc Func _Interrupt() ; The HotKey was pressed so set the flag $fInterrupt = 2 EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; The Func 2 button was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 ; The dummy control was actioned by the Accelerator key so set the flag If BitAND($wParam, 0x0000FFFF) = $hAccelInterupt Then $fInterrupt = 3 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND
  2. Hello, i was wondering how could i stop a loop with a button here is my code #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 623, 444, 192, 114) Global $StartButton = GUICtrlCreateButton("Button1", 88, 192, 171, 25) Global $EndButton = GUICtrlCreateButton("Button2", 320, 192, 203, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $var = 1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $StartButton Start() Case $EndButton Stop() EndSwitch WEnd Func Start() While $var = 1 ConsoleWrite("again" & @CRLF) WEnd EndFunc Func Stop() $var = 0 EndFunc i was reading https://www.autoitscript.com/wiki/Interrupting_a_running_function but still i could not figure it out help PLZ !
×
×
  • Create New...