Jump to content

Recommended Posts

Posted (edited)

The button event should be triggered whenever I press the enter key but it isn't.

Opt("GUIOnEventMode", 1)

$g = GUICreate("gui")
$i = GUICtrlCreateInput("",2,2)
$b = GUICtrlCreateButton("click me",220,2)
GUICtrlSetStyle($b, 0x50034001);defpushbutton

GUICtrlSetOnEvent($b, "_button")
GUISetOnEvent(-3, "_Close")
GUISetState()

While 1
    Sleep(100)
WEnd

Func _button()
    MsgBox(0,"","Yay!")
EndFunc

Func _Close()
    Exit
EndFunc

It works if I set the defpushbutton style in the GUICtrlCreateButton() function but I need to set reset the style many times in my script (when the first style is not $BS_DEFPUSHBUTTON).

Edited by Info
Posted
Posted

@KaFu

Not entirely true. Remove the input control and try. I get the same behavior on Win7 x64. If the DEFPUSH style is set in the call to GuiCtrlCreateButton then everything works correctly. Otherwise, same bug as OP.

Posted (edited)

You're right, it's not the input control.

$BS_DEFPUSHBUTTON = "Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default."

A dialog box seems to be a window with special attributes and esp. messages, guess thats where the dog is burried (German saying :blink:)...

Edited by KaFu
Posted (edited)

You were on to something with the dialog bit. I think there's an internal AutoIt window setting or message processing feature that needs to be 'activated'. This ugly hack works properly.

Opt("GUIOnEventMode", 1)

$g = GUICreate("gui")
$i = GUICtrlCreateInput("",2,2)
; UGLY HACK
GUICtrlDelete(GUICtrlCreateButton("" ,0 , 0, 0, 0, 1)) ; BS_DEFPUSHBUTTON
; =========
$b = GUICtrlCreateButton("click me",220,2)
GUICtrlSetStyle($b, 0x10001);ws_tabstop + defpushbutton

GUICtrlSetOnEvent($b, "_button")
GUISetOnEvent(-3, "_Close")
GUISetState()

While 1
    Sleep(100)
WEnd

Func _button()
    MsgBox(0,"","Yay!")
EndFunc

Func _Close()
    Exit
EndFunc

I'd still probably report this as a bug...

Edited by wraithdu

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
×
×
  • Create New...