FlexScott Posted February 6, 2018 Share Posted February 6, 2018 I've created an GUI to run a test program, and I'd like the operator to still be able to use the exit button while in one of the functions called from the GUI. I'm able to change the label and enable/disable the button while in another function, but I'm not having any luck detecting the button click. I've added the "global" designations recently (just guessing at a potential solution), but that didn't seem to make any difference. How do I check for the button click events related to this GUI outside of the initial While loop? Thanks for your help! autoit_example.txt Link to comment Share on other sites More sharing options...
Earthshine Posted February 6, 2018 Share Posted February 6, 2018 (edited) how about a hot pause key kind of thing? modify to make it exit maybe? just a thought. Control-X is usually an exit from an console app. #include <Timers.au3> ; Create a hot key. I'm using the "Pause/Break" key typically located near the number pad on the keyboard. The keycode for this key is simply "{PAUSE}" HotKeySet("{PAUSE}", "_togglePause") ; Create a Boolean (True of False variable) to tell your program whether or not your program is paused or unpaused. Set it equal to 'False' so the script is running by default. Global $isPaused = False ; #FUNCTION# ==================================================================================================================== ; Name ..........: _togglePause ; Description ...: Pause your scripts during execution for debug ; Syntax ........: togglePause () ; Parameters ....: None ; Return values .: None ; Author ........: root ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; ===============================================================================================================================; Create the togglePause function to stop/start the script Func _togglePause () ; When this function is initiated, the code on the next line 'toggles' the variable to True/False. If the script is unpaused (the $isPaused variable is set to 'False') then the next line will change it to 'True' and vice versa. $isPaused = NOT $isPaused ; Create a while loop to stall the program ; The line below is the same thing as "While $isPaused == True" While $isPaused ; This code will run constantly until the $isPaused variable is set to 'True'. To make the script do nothing, simply add a sleep command. Sleep(100) WEnd EndFunc Edited February 6, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted February 6, 2018 Share Posted February 6, 2018 and, your code posted does not compile. you can attach an .au3 file too, no need for text. also you can post code here using the CODE <> tags My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 6, 2018 Moderators Share Posted February 6, 2018 FlexScott, Welcome to the AutoIt forums. To detect button presses while functions are running, take a look at the Interrupting a running function tutorial in the Wiki. M23 Earthshine 1 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...
FlexScott Posted February 6, 2018 Author Share Posted February 6, 2018 2 hours ago, FlexScott said: I've created an GUI to run a test program, and I'd like the operator to still be able to use the exit button while in one of the functions called from the GUI. I'm able to change the label and enable/disable the button while in another function, but I'm not having any luck detecting the button click. I've added the "global" designations recently (just guessing at a potential solution), but that didn't seem to make any difference. How do I check for the button click events related to this GUI outside of the initial While loop? Thanks for your help! autoit_example.txt Thanks Melba! That looks like what I need to know. Hopefully I can meld aspects of the MessageLoop and OnEvent modes. Now to experiment... Thanks very much! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 6, 2018 Moderators Share Posted February 6, 2018 FlexScott, Quote Hopefully I can meld aspects of the MessageLoop and OnEvent modes Be very careful here - it would be much better to have just the one mode throughout the script. Come back if you have problems. 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...
FlexScott Posted February 6, 2018 Author Share Posted February 6, 2018 I don't actually want to interrupt a running function, I just need to be able to check to see if the button has been clicked at certain points so I can control the actual exit(s). The machine being tested has lots of motors and sensors, so I don't want to just bail at any time leaving it in an indeterminate state. But I want to give the operator the option to detour out at certain points. Thanks again! Link to comment Share on other sites More sharing options...
FlexScott Posted February 6, 2018 Author Share Posted February 6, 2018 Sorry, I meant to add that I was able to enable and disable (gray-out) the button from the various test functions, so I can make it clear to the operator when this is an option. I just couldn't figure out how to determine if the button had been clicked at the potential exit points. 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