Luigi

after disable a button, the script not exit on press ESC button

17 posts in this topic

#1 ·  Posted (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.

#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 by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites



#2 ·  Posted

Have you tried using HotKeySet?

Share this post


Link to post
Share on other sites

#3 ·  Posted

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).


m(o.O)m

Share this post


Link to post
Share on other sites

#4 ·  Posted

You can use the same function as $GUI_EVENT_CLOSE for example:

HotKeySet("{ESC}", "Quit")

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#6 ·  Posted

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?

Share this post


Link to post
Share on other sites

#7 ·  Posted

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?


m(o.O)m

Share this post


Link to post
Share on other sites

#8 ·  Posted

You mean, adding new button, the script won't ESC?

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#10 ·  Posted

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.

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@Subz, hum... SpecialEvents does not work anymore after $GUI_DISABLE.

 

Edited by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#12 ·  Posted (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.

#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 by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#13 ·  Posted

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._______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

#14 ·  Posted

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.

1 person likes this

Share this post


Link to post
Share on other sites

#15 ·  Posted (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! ^^

#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 by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#16 ·  Posted

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._______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

#17 ·  Posted

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.

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