dangwu1 Posted November 9, 2011 Share Posted November 9, 2011 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 9, 2011 Moderators Share Posted November 9, 2011 dangwu1,You could use a HotKey to set a flag and then check for that flag in an Adlib function: ; 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 EndFuncAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted November 9, 2011 Share Posted November 9, 2011 I'm curious M23. Is there benefit or good practice to set a flag, rather than just exit the script in the _Exit_Flag() function? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 9, 2011 Moderators Share Posted November 9, 2011 JohnOne, Oops! None whatsoever - must be age creeping up on me! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
dangwu1 Posted November 9, 2011 Author Share Posted November 9, 2011 Works perfectly, thanks. Link to comment Share on other sites More sharing options...
storme Posted November 10, 2011 Share Posted November 10, 2011 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 FunJohn Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
JohnOne Posted November 10, 2011 Share Posted November 10, 2011 must be age creeping up on me! M23It 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. Link to comment Share on other sites More sharing options...
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