Jump to content
Sign in to follow this  
MariusN

Hitting ENTER instead of SPACEBAR

Recommended Posts

MariusN

I have a button in my gui that has the word "OK" as a "GUICtrlCreateButton" and accepts the SAPCEBAR when i press it. Is there a way it can recognize the ENTER button as well instead of the SPACEBAR....or BOTH?

Edited by MariusN

Share this post


Link to post
Share on other sites
Fantastic

The control which has focus will catch "Spacebar".

The control which is defined as $BS_DEFPUSHBUTTON will catch "Enter".

Last I think that first created control has focus by default (except controls that don't get focus)

Now work it out a little and you will get it.

An example here (sorry for the script it's big, it was just a quick take from forum)

#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#NoTrayIcon

Global $Form1
_aka()

Func _aka()

    $Form1 = GUICreate("MAIN GUI", 265, 137)
    $Button1 = GUICtrlCreateButton("About", 24, 72, 73, 25)
    $nope = GUICtrlCreateButton("Exit", 168, 72, 73, 25, $BS_DEFPUSHBUTTON)
    $Label1 = GUICtrlCreateLabel("This is a GUI 1`S LABEL", 72, 24, 120, 17)
    $hfilemenu = GUICtrlCreateMenu("File")
    $hfilemenu_fisrtitem = GUICtrlCreateMenuItem("About", $hfilemenu)
    GUICtrlCreateMenuItem("", $hfilemenu)
    $hfilemenu_itemEXIT = GUICtrlCreateMenuItem("Exit", $hfilemenu)
    GUICtrlCreateMenuItem("", $hfilemenu)
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $hfilemenu_fisrtitem
                _haqqda()
            Case $hfilemenu_itemEXIT
                ;confirm exit
                $hanswer = MsgBox(65, "Do You Want Exit?", "Dou You Want Exit?", 15) ; timeout=15 sec
                If $hanswer = "1" Then ; 1 <= mean OK. See the help file of Autoit for msgbox() You can find about it :)
                    Exit
                EndIf

            Case $Button1

                _haqqda()
            Case $nope
                $hanswer = MsgBox(65, "Do You Want Exit?", "Dou You Want Exit?", 15) ; timeout=15 sec
                If $hanswer = "1" Then ; 1 <= mean OK. See the help file of Autoit for msgbox() You can find about it :)
                    Exit
                EndIf




        EndSwitch
    WEnd
EndFunc ;==>_aka

Func _haqqda()
    GUIDelete($Form1) ;deleting $Form1 . This is a previous GUI .
    $Form2 = GUICreate("About", 324, 234) ;creating second GUI .In that case this is a <ABOUT> GUI.
    $Label1 = GUICtrlCreateLabel("Product Name", 152, 24, 72, 17, BitOR($SS_NOTIFY, $WS_GROUP, $WS_VISIBLE, $WS_CHILD))
    $Label2 = GUICtrlCreateLabel("Version", 152, 48, 39, 17, BitOR($SS_NOTIFY, $WS_GROUP, $WS_VISIBLE, $WS_CHILD))
    $Label4 = GUICtrlCreateLabel("Comments: ", 16, 160, 53, 17, BitOR($SS_NOTIFY, $WS_GROUP, $WS_VISIBLE, $WS_CHILD))
    $Label3 = GUICtrlCreateLabel("sh3llc043r", 16, 136, 48, 17, BitOR($SS_NOTIFY, $WS_GROUP, $WS_VISIBLE, $WS_CHILD))
    $Button2 = GUICtrlCreateButton("&OK", 112, 208, 75, 25, BitOR($WS_TABSTOP, $WS_VISIBLE, $WS_CHILD))
    $Image1 = GUICtrlCreatePic(@SystemDir & "\oobe\html\mouse\images\pisa.jpg", 16, 24, 105, 97, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUISetState()
    SoundPlay(@WindowsDir & "\media\tada.wav", 0)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg


            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)

                _aka()



            Case $Button2
                GUIDelete($Form2) ;deleting <ABOUT> GUI
                _aka() ;creating 1`st GUI again. For func see below => Func _aka()

        EndSwitch


    WEnd

EndFunc ;==>_haqqda
Edited by Fantastic

Share this post


Link to post
Share on other sites
MariusN

The control which has focus will catch "Spacebar".

The control which is defined as $BS_DEFPUSHBUTTON will catch "Enter".

Last I think that first created control has focus by default (except controls that don't get focus)

Now work it out a little and you will get it.

thanks...it worked like a charm :mellow: Edited by MariusN

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
Sign in to follow this  

×