Xichael Posted September 4, 2016 Posted September 4, 2016 (edited) $BS_DEFPUSHBUTTON successfully assigns the Enter key to a default button, but Spacebar still gets assigned to whichever button comes first in the GUI. How can I get both Enter & Spacebar to trigger the same button? Here's some code + a pic of the problem: #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) GUICreate("Test", 200, 200, -1, -1, $WS_POPUP + $WS_BORDER) GUICtrlCreateButton("Button 1", 10, 15, 180, 50) GUICtrlSetOnEvent(-1, "Button1") Func Button1() MsgBox(0,"","Button 1") EndFunc GUICtrlCreateButton("Button 2", 10, 70, 180, 50) GUICtrlSetOnEvent(-1, "Button2") Func Button2() MsgBox(0,"","Button 2") EndFunc GUICtrlCreateButton("Cancel", 25, 130, 150, 50, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "Cancel") Func Cancel() Exit EndFunc GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Edited September 18, 2016 by Xichael
Developers Jos Posted September 4, 2016 Developers Posted September 4, 2016 Maybe use HotKeySet() or the space and preform the action you want? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
kylomas Posted September 4, 2016 Posted September 4, 2016 Xichael, Try this... #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1) GUICreate("Test", 200, 200, -1, -1, $WS_POPUP + $WS_BORDER) local $idButton01 = GUICtrlCreateButton("Button 1", 10, 15, 180, 50) GUICtrlSetOnEvent(-1, "Button1") Func Button1() MsgBox(0, "", "Button 1") EndFunc ;==>Button1 GUICtrlCreateButton("Button 2", 10, 70, 180, 50) GUICtrlSetOnEvent(-1, "Button2") Func Button2() MsgBox(0, "", "Button 2") EndFunc ;==>Button2 local $idbuttoncancel = GUICtrlCreateButton("Cancel", 25, 130, 150, 50, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "Cancel") Func Cancel() Exit EndFunc ;==>Cancel Local $aAccelKeys[1][2] = [["{SPACE}", $idButton01]] GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Xichael Posted September 18, 2016 Author Posted September 18, 2016 (edited) Thanks, guys. I've found a solution... Instead of: GUICtrlCreateButton("Cancel", 25, 130, 150, 50, $BS_DEFPUSHBUTTON) I have to use: GUICtrlCreateButton('Cancel', 25, 130, 150, 50) GUICtrlSetState(-1, $GUI_FOCUS) Edited September 18, 2016 by Xichael
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