Jump to content

Stopping a while loop


Spask
 Share

Recommended Posts

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.

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

Or, you could do something like this...

 

#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

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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