Sign in to follow this  
Followers 0
charvi

Input with focused button

4 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

use $BS_DEFPUSHBUTTON as a style for the button, then you can make a function that is triggered by the push of that button.search it in the help file

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
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)

Share this post


Link to post
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 :)

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  
Followers 0