Spask Posted October 11, 2017 Posted October 11, 2017 (edited) Hi, I've made a script with a while loop in it but I can't figure out how to stop the loop while it's running. expandcollapse popup$np = Run("notepad.exe") #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $bot = GUICreate("AutoIT bot", 226, 126, -1, -1) Global $startloop = GUICtrlCreateButton("Start Loop", 32, 56, 75, 25) Global $pauseloop = GUICtrlCreateButton("Pause Loop", 112, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $var = 1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;starts loop Case $startloop startloop() ;should Pause loop, but does not work Case $pauseloop Pauseloop() EndSwitch WEnd Func startloop() $var = 1 WinActivate ("untitled") While $var = 1 Send("test") Send("{ENTER}") WEnd EndFunc Func Pauseloop() $var = 2 EndFunc The while loop starts at line 36 Edited October 11, 2017 by Spask
232showtime Posted October 11, 2017 Posted October 11, 2017 check here Spask 1 ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
czardas Posted October 11, 2017 Posted October 11, 2017 Read this article and run the examples: https://www.autoitscript.com/wiki/Interrupting_a_running_function Spask 1 operator64 ArrayWorkshop
ripdad Posted October 11, 2017 Posted October 11, 2017 Or, you could do something like this... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Run("notepad.exe") Global $bot = GUICreate("AutoIT bot", 226, 126, -1, -1) Global $startloop = GUICtrlCreateButton("Start Loop", 32, 56, 75, 25) Global $pauseloop = GUICtrlCreateButton("Pause Loop", 112, 56, 75, 25) GUICtrlSetOnEvent($startloop, 'Startloop') GUICtrlSetOnEvent($pauseloop, 'Pauseloop') GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitApp') Opt('GUIOnEventMode', 1) GUISetState(@SW_SHOW) Global $var = 0 While 1 While $var = 1 Sleep(250) WinActivate("Untitled - Notepad") Send("test{ENTER}") WEnd Sleep(10) WEnd Func Startloop() $var = 1 EndFunc Func Pauseloop() $var = 2 EndFunc Func ExitApp() Opt('GUIOnEventMode', 0) GUIDelete($bot) Exit EndFunc Spask 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now