Jump to content

Input with focused button


charvi
 Share

Recommended Posts

Hi,

Perhaps an easy one.....

How can I make an input so that when the user hits the [Enter] key, the OK button is activated?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Color.au3>
#include <INet.au3>
#include <Memory.au3>

_Login_Password_()

Func _Login_Password_()

    Local $h_Login_Password, $h_Login_Password_Win, $h_Login_Password_Label
    Local $h_Login_Password_Btn1, $h_Login_Password_Btn3, $h_Login_Password_Btn4
    local $ah_Input[1]

    $h_Login_Password_Win = GUICreate("Login", 560, 216, -1, -1, $WS_DLGFRAME)

    $h_Login_Password_Label = GUICtrlCreateLabel("Password:", 20, 50)
    
    $ah_Input[0] = GUICtrlCreateInput("", 120, 50, 300, 20, $ES_PASSWORD, 0)
    GUICtrlSetBkColor(-1, 0xffffff)
    GUICtrlSetColor(-1, 0x000000)

    $h_Login_Password_Btn3 = GUICtrlCreateButton("OK", 300, 150, 100, 30)
    $h_Login_Password_Btn4 = GUICtrlCreateButton("Cancel", 440, 150, 100, 30)
    
    GUICtrlSetState($h_Login_Password_Btn3, $GUI_FOCUS); the focus is on this button
    GUISetState()

    While 1
        $i_Msg = GUIGetMsg()
        Switch $i_Msg
            Case $h_Login_Password_Btn3
                MsgBox(0,"OK","The OK button is selected")
                ExitLoop
            Case $h_Login_Password_Btn4
                Exit
        EndSwitch
    WEnd
    GUIDelete($h_Login_Password_Win)
EndFunc
Link to comment
Share on other sites

One way to do it is to use the style $BS_DEFPUSHBUTTON on your "OK"-button, simply change

$h_Login_Password_Btn3 = GUICtrlCreateButton("OK", 300, 150, 100, 30)

to

$h_Login_Password_Btn3 = GUICtrlCreateButton("OK", 300, 150, 100, 30, $BS_DEFPUSHBUTTON)
Link to comment
Share on other sites

One way to do it is to use the style $BS_DEFPUSHBUTTON on your "OK"-button, simply change

$h_Login_Password_Btn3 = GUICtrlCreateButton("OK", 300, 150, 100, 30)

to

$h_Login_Password_Btn3 = GUICtrlCreateButton("OK", 300, 150, 100, 30, $BS_DEFPUSHBUTTON)
Perfect ! Thank you AoRaToS and AdmiralAlkex :)
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...