Jump to content

Assign both Enter & Spacebar to Default Button


Xichael
 Share

Recommended Posts

$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

 

BS_DEFPUSHBUTTON.png

Edited by Xichael
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...