Luigi Posted March 13, 2017 Share Posted March 13, 2017 (edited) Greetings! If you open the script and press ESC (to exit), the script exit fine. If you click in the button, to disable it, whe you press ESC (to exit), for me, the windows play a sound and not exit. This is happens to you? Why? How solve it? Obs: I preffer use events in script. Best regards. expandcollapse popup#include-once #include <Array.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global $aGuiSize[2] = [320, 240] Global $sGuiTitle = "GuiTitle" Global $hGui Global $hButton $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $hButton = GUICtrlCreateButton("Click here!", 10, 10, 80, 25) GUICtrlSetOnEvent($hButton, "ButtonClick") GUISetState(@SW_SHOW, $hGui) While Sleep(25) WEnd Func ButtonClick() GUICtrlSetState($hButton, $GUI_DISABLE) EndFunc Func OnExit() GUISetState($hGui, @SW_HIDE) GUIDelete($hGui) EndFunc ;==>OnExit Func Quit() Exit EndFunc ;==>Quit Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Subz Posted March 13, 2017 Share Posted March 13, 2017 Have you tried using HotKeySet? Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 I try, but I thinking HotKeySet is to link a function to a key. I need link a function to a Button (or other GuiCtrl element). Visit my repository Link to comment Share on other sites More sharing options...
Subz Posted March 13, 2017 Share Posted March 13, 2017 You can use the same function as $GUI_EVENT_CLOSE for example: HotKeySet("{ESC}", "Quit") Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) @Subz, its work, but, have a problem. I you click ESC out of script, it will be finished. This is not wanted. WIth HotKeySet, you need write more code to verify each loop, if this script is on focus or not, and enable HotKeySet(ESC) or not in focus, disable HotKeySet(ESC). Try it. Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Subz Posted March 13, 2017 Share Posted March 13, 2017 Sorry don't understand, your OP implied you wanted Esc to exit your script, which is what it does when the button is not disabled. Can you explain what behavior you are expecting from the escape key? Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 Sorry my english... If you do not click on button, the run of script is normal. If you press ESC, they exit, this is good way. If you click a button, when you use GUICtrlSetState($hButton, $GUI_DISABLE) for this or any GUICtrlCreateButton, the ESC key does not work anymore. For me, the Windows play a error sound and script not exit with ESC key, I need click on "X" to exit. Why the script lost the function of ESC? Visit my repository Link to comment Share on other sites More sharing options...
KickStarter15 Posted March 13, 2017 Share Posted March 13, 2017 You mean, adding new button, the script won't ESC? Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) @KickStarter15, this issue is old for me. With one or many button (or other elements: GuiCtrlCreateInput, GuiCtrlCreateCombo, GuiCtrlCreateEdit)... When you use only one GUICtrlSetState($HandleOfAnyElement, $GUI_DISABLE) the ESC not work any more. Of course... If you GUICtrlSetState($HandleOfAnyElement, $GUI_ENABLE), the ESC recover the function, and Exit fine. $GUI_DISABLE disable only element or disable the GUI? In the AutoIt's HELP say: "Control will be greyed out." Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Subz Posted March 13, 2017 Share Posted March 13, 2017 Not 100% sure maybe someone else can answer, but when you press escape it sends a notification of -3 or $GUI_EVENT_CLOSE to the button control, when the button is disabled it no longer accepts any notifications. So if you were to add another dummy control and after disabling the first button you clicked on the dummy control you can send notifications again to that non disabled control. Hope that makes sense. Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) @Subz, hum... SpecialEvents does not work anymore after $GUI_DISABLE. Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) A "virtual way" to DISABLE the button, is unsign the function from button, and re-paint it like a disable button. When ENABLE it again, assing the function to the button and re-paint like a enabled button. I do not find this elegant solution, but it works. I still do not know if the error is mine or I'm not using the code the right way. The button was never DISABLED, I remove the function's link. You can click, but, does not work. expandcollapse popup#include-once #include <Array.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global $aGuiSize[2] = [320, 240] Global $sGuiTitle = "GuiTitle" Global $hGui Global $hLock, $hUnLock $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents", $hGui) $hLock = GUICtrlCreateButton("Lock me!", 10, 10, 80, 25) GUICtrlSetOnEvent($hLock, "ButtonDisable") $hUnLock = GUICtrlCreateButton("Unlock!", 10, 40, 80, 25) GUICtrlSetOnEvent($hUnLock, "ButtonEnable") GUISetState(@SW_SHOW, $hGui) While Sleep(25) WEnd Func ButtonDisable() GUICtrlSetBkColor($hLock, 0xCCCCCC) GUICtrlSetColor($hLock, 0x9090A8) GUICtrlSetOnEvent($hLock, "") EndFunc ;==>ButtonDisable Func ButtonEnable() GUICtrlSetBkColor($hLock, 0xE1E1E1) GUICtrlSetColor($hLock, 0x5A005A) GUICtrlSetOnEvent($hLock, "ButtonDisable") EndFunc ;==>ButtonEnable Func OnExit() GUIDelete($hGui) EndFunc ;==>OnExit Func SpecialEvents() ConsoleWrite("@GUI_CtrlId[ " & @GUI_CtrlId & " ]" & @LF) Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc ;==>SpecialEvents Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2017 Moderators Share Posted March 13, 2017 Luigi, I have been playing with this all morning. In both OnEvent and MessageLoop mode, disabling a control programmatically after the GUI has been displayed prevents the ESCAPE key from exiting the GUI. Setting the control to disabled before the GUI is displayed does not have this effect. Unless someone can come up with a logical explanation it looks like a bug to me - I suggest opening a Trac ticket and linking to this thread. 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...
Subz Posted March 13, 2017 Share Posted March 13, 2017 In Post#11 remove the GUICtrlSetOnEvent($hUnLock, "ButtonEnable") function so it now does nothing, click "Lock me!" its now disabled and escape doesn't work, now click the "Unlock" button (it does nothing) but if you press escape it will now close. As mentioned above when you click "Lock me!" the focus is still on that disabled button which no longer accepts notifications, you have to change the focus to a non disabled control which will accept notifications. Luigi 1 Link to comment Share on other sites More sharing options...
Luigi Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) @Melba23, WOW! This is not my error? @Subz, you are right! Just write on line of code and redirect the focus for another ENABLED GuiCtrlElement! GUICtrlSetState($hUnLock, $GUI_FOCUS) Thank you! ^^ expandcollapse popup#include-once #include <Array.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global $aGuiSize[2] = [320, 240] Global $sGuiTitle = "GuiTitle" Global $hGui Global $hLock, $hUnLock $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents", $hGui) $hLock = GUICtrlCreateButton("Lock me!", 10, 10, 80, 25) GUICtrlSetOnEvent($hLock, "ButtonDisable") $hUnLock = GUICtrlCreateButton("Unlock!", 10, 40, 80, 25) GUICtrlSetOnEvent($hUnLock, "ButtonEnable") GUISetState(@SW_SHOW, $hGui) While Sleep(25) WEnd Func ButtonDisable() GUICtrlSetState($hLock, $GUI_DISABLE) GUICtrlSetState($hUnLock, $GUI_FOCUS) ;~ GUICtrlSetBkColor($hLock, 0xCCCCCC) ;~ GUICtrlSetColor($hLock, 0x9090A8) ;~ GUICtrlSetOnEvent($hLock, "") EndFunc ;==>ButtonDisable Func ButtonEnable() GUICtrlSetState($hLock, $GUI_ENABLE) ;~ GUICtrlSetBkColor($hLock, 0xE1E1E1) ;~ GUICtrlSetColor($hLock, 0x5A005A) ;~ GUICtrlSetOnEvent($hLock, "ButtonDisable") EndFunc ;==>ButtonEnable Func OnExit() GUIDelete($hGui) EndFunc ;==>OnExit Func SpecialEvents() ConsoleWrite("@GUI_CtrlId[ " & @GUI_CtrlId & " ]" & @LF) Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc ;==>SpecialEvents Edited March 13, 2017 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2017 Moderators Share Posted March 13, 2017 Subz, Even though your workaround solves the problem, I am not sure your explanation is logical. $GUI_EVENT_CLOSE is, as its name suggests, a GUI event, not a control one. So I would expect it to be sent even if the currently focused control is disabled - but I freely admit have no knowledge of how AutoIt deals with this internally. 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...
Subz Posted March 13, 2017 Share Posted March 13, 2017 Melba23 In the beginning I expected the same behavior you described as well, it wasn't until I created a dummy button and couldn't tab between controls either, when the focus was on the disabled button, that I gathered that the keys were being sent to the control not to the Gui, so my explanation is really around observational behavior, but have no idea if this is correct or not. 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