Jump to content

Stopping a While 1 loop?


jgq85
 Share

Recommended Posts

I've got together a test script from a GUI and doe fine what I want it to, but I'm having trouble figuring out how to stop the loop from running when I think it's a good time to stop it.

Once this is running I have no way to stop it but to close AutoIt down completely

Any command or button or hotkey I can use to stop it from running?

Func _AssetURLStrLoop()

While 1
Sleep(300)
WinActivate("Microsoft Word", "")
Sleep(300)
Send("^c")
Sleep(300)
Send("^k")
;~ Send("{TAB}{TAB}{TAB}{TAB}")
Sleep(300)
Send("www.google.com" & "^v")
Sleep(300)
Send("{Enter}")
Send("{RIGHT}")
Send("{DOWN}")
Send("+{HOME}")
WEnd

[size=4]EndFunc[/size]
Link to comment
Share on other sites

You can set an hotkey:

HotKeySet("{ESC}", "Terminate")

_AssetURLStrLoop()

Func _AssetURLStrLoop()
    While 1
        Sleep(300)
        WinActivate("Microsoft Word", "")
        Sleep(300)
        Send("^c")
        Sleep(300)
        Send("^k")
;~ Send("{TAB}{TAB}{TAB}{TAB}")
        Sleep(300)
        Send("www.google.com" & "^v")
        Sleep(300)
        Send("{Enter}")
        Send("{RIGHT}")
        Send("{DOWN}")
        Send("+{HOME}")
    WEnd
EndFunc   ;==>_AssetURLStrLoop

Func Terminate()
    Exit
EndFunc

When you think that everything is fine just press the esc key ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

  • Developers

Cool thanks guys

Why did you report your own comment?

Guess you wanted to reply...

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It appears that the ESC key will only work to terminate the script of my GUI script is idle.

However, if I click the button that triggers the While loop, ESC won't work. Script will just run endlessley, and no hotkeys will work. I have to go into the script editor and break the script from there.

GUI:

[size=4]$Form1_1 = GUICreate("Incident Manager", 328, 203, 281, 625, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))[/size]
GUISetBkColor(0x00FFFF)
$AssetURLStr = GUICtrlCreateButton("AssetURLStr", 104, 87, 89, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUI Button case:

[size=4]While 1[/size]
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $AssetURLStrLoop
_AssetURLStrLoop()
EndSwitch
WEnd

Button's script:

[size=4]Func _AssetURLStrLoop()
While 1
Sleep(300)
WinActivate("Microsoft Word", "")
Sleep(300)
Send("^c")
Sleep(300)
Send("^k")
Sleep(300)
Send("www.google.com" & "^v")
Sleep(300)
Send("{Enter}")
Send("{RIGHT}")
Send("{DOWN}")
Send("+{HOME}")
WEnd
EndFunc

Edit: Why do these forums keep adding tags to my text?

Edited by jgq85
Link to comment
Share on other sites

Try this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}", "Terminate")

Global $paused = False


$Form1_1 = GUICreate("Incident Manager", 328, 203, 281, 625, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetBkColor(0x00FFFF)
$AssetURLStr = GUICtrlCreateButton("AssetURLStr", 104, 87, 89, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ##

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $AssetURLStr
            _AssetURLStrLoop()
    EndSwitch
WEnd

Func _AssetURLStrLoop()
    While $paused = False
        WinActivate("Microsoft Word", "")
        Sleep(300)
        Send("^c")
        Sleep(300)
        Send("^k")
        Sleep(300)
        Send("www.google.com" & "^v")
        Sleep(300)
        Send("{Enter}")
        Send("{RIGHT}")
        Send("{DOWN}")
        Send("+{HOME}")
    WEnd
    ;Exit ;Uncomment this if you wanna exit
EndFunc   ;==>_AssetURLStrLoop

Func Terminate()
    $paused = True
EndFunc   ;==>Terminate
Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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