PhilHibbs Posted March 17, 2010 Share Posted March 17, 2010 I think I need to re-think the way I get my scripts to terminate. Currently I just use HotKeySet("{Esc}","ExitScript"), but this doesn't work if I'm running more than one script at a time. Perhaps I should use _IsPressed in my While True loop. Any other suggestions? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 17, 2010 Moderators Share Posted March 17, 2010 PhilHibbs,You can look for various things in the GUIGetMsg loop; $GUI_EVENT_CLOSE (produced by the red [X] of the GUI itself) or the ControlIDs of a suitable control or menu item you have created. If you want to use a tray item, you need to use TrayGetMsg - or use TrayItemSetOnEvent.An example:#include <GUIConstantsEx.au3> ; Create tray menu Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "On_Exit") TraySetState() ; Create GUI $hGUI = GUICreate("Test", 500, 500) $mFileMenu = GUICtrlCreateMenu("&File") $mExitItem = GUICtrlCreateMenuItem("&Exit", $mFileMenu) $hExitButton = GUICtrlCreateButton("Exit", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $mExitItem, $hExitButton Exit EndSwitch WEnd Func On_Exit() Exit EndFuncThere is also Opt(GUICloseOnESC) which basically sends $GUI_EVENT_CLOSE when you press Escape - yet another exit point unless you disable it.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...
PhilHibbs Posted March 17, 2010 Author Share Posted March 17, 2010 You can look for various things in the GUIGetMsg loop; I don't see how any of that helps me to make my script exit when I press {Esc} regardless of what window is active. One of us is misunderstanding the other. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 17, 2010 Moderators Share Posted March 17, 2010 PhilHibbs, One of us is misunderstanding the otherI quite agree. Perhaps Accelerators might help you. Run this script twice from SciTE, or better compile it, copy it and rename the copy. You will find that pressing "Esc" only exits the active script. #include <GUIConstantsEx.au3> Opt("GUICloseOnESC", 0) ; prevent normal ESC = Exit $hGUI = GUICreate(@ScriptName, 500, 500) $hDummy = GUICtrlCreateDummy() GUISetState() Dim $AccelKeys[1][2]=[["{ESC}", $hDummy]] GUISetAccelerators($AccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hDummy ConsoleWrite("Hit" & @CRLF) Exit EndSwitch WEnd I hope we are on the same page this time. 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...
PhilHibbs Posted March 17, 2010 Author Share Posted March 17, 2010 I hope we are on the same page this time. Not quite. The scripts I'm talking about don't have a GUI. They run in the background and interact with another application window. If I'm running more than one of them, I want them all to exit when I press {Esc}. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 17, 2010 Moderators Share Posted March 17, 2010 PhilHibbs, It might have helped to give a bit more information in the first post. My last suggestion: Run a mother script which looks over its offspring and then terminates them all if one is closed. If you were to use this script as the launcher for the others (as you say you need a variable number running at any one time) it would be really simple to collect the PIDs and so keep an eye on them. 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...
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