Jump to content
Sign in to follow this  
jgq85

Stopping a While 1 loop?

Recommended Posts

jgq85

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]

Share this post


Link to post
Share on other sites
Nessie

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!

  • Like 1

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

Share this post


Link to post
Share on other sites
DicatoroftheUSA

Or you can click the tray item and choose exit.

If you do not wish it to exit entirely, have the hotkey function toggle a global variable that through an if then statement will trigger the exitloop function.

  • Like 1

Share this post


Link to post
Share on other sites
jgq85

Cool thanks guys

Share this post


Link to post
Share on other sites
Jos

Cool thanks guys

Why did you report your own comment?

Guess you wanted to reply...

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jgq85

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

Share this post


Link to post
Share on other sites
Nessie

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

Share this post


Link to post
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
Sign in to follow this  

×