Sign in to follow this  
Followers 0
dangwu1

Terminate script mid-run?

7 posts in this topic

How do you stop a long script (composed of a long series of mouseclicks and key sends) from executing completely when it's running? I know if you run from SciTe you can open that window and ctrl+break, but sometimes the script has control of that mouse so that's difficult.

Thanks.

Share this post


Link to post
Share on other sites



dangwu1,

You could use a HotKey to set a flag and then check for that flag in an Adlib function: :oops:

; Set the HotKey
HotKeySet("x, "_Exit_Flag")

; Clear the flag
Global $fExit = False

; Create the Adlib timer
AdlibRegister("_Exit_Check")

; Here is your long list - we will loop to make it everlasting
While 1
    MouseClick("left")
    Send("a")

    Sleep(10) ; Just to prevent CPU load in the example
WEnd

Func _Exit_Flag()
    ; The HotKey sets the flag
    $fExit = True
EndFunc

Func _Exit_Check()
    ; The Adlib function exits if the flag is set
    If $fExit Then Exit
EndFunc

All clear? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

JohnOne,

Oops! :D

None whatsoever - must be age creeping up on me! :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Works perfectly, thanks.

Share this post


Link to post
Share on other sites

There is a good use for an EXIT FLAG.

IF the code is in a vital place..(ie it's opened a program to do something) it's messy to just leave it there for the user to clean up.

All you have to do it put calls to "_Exit_Check" at "safe" places...IE don't use adlib.

I've got an abort button on one of my programs. The program uses a few external programs and it wouldn't be good to leave them running for the user to cleanup.

When I click the abort button I set the flag, then I check for the flag in loops and such and elegantly exit the program, cleanup as I go if the flag has been set.

Have Fun

John Morrison

Share this post


Link to post
Share on other sites

must be age creeping up on me! :oops:

M23

:D

It never crept up on me, I woke up one morning and it punched me in the face.

storme, sorry I meant in this long list of mouse clicks scenario.

Of course you could also clean up your scripts business inside an exit function too.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  
Followers 0