Info Posted July 20, 2010 Share Posted July 20, 2010 (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 July 20, 2010 by Info Link to comment Share on other sites More sharing options...
wraithdu Posted July 20, 2010 Share Posted July 20, 2010 Yep, seems like a bug to me as well. You should search Trac and see if there's a bug ticket already, and if not you should create one. Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 Guess it has something to do with the Input control, seems like the first input aquires Focus by default, kind of greedy behavior . As a workaround use GUICtrlSetState($b, $GUI_FOCUS). OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
wraithdu Posted July 20, 2010 Share Posted July 20, 2010 @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. Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 (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 )... Edited July 20, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
wraithdu Posted July 20, 2010 Share Posted July 20, 2010 (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 July 20, 2010 by wraithdu 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