Jump to content
Sign in to follow this  
AmphetaMarinE

How to make the "Enter" key Always click the OK Button?

Recommended Posts

AmphetaMarinE

Hi Guys,

In a gui I am designing, the first thing the user sees is a login prompt, with input controls for username and password, a login button, and a cancel button, as per the following...

$Username = GUICtrlCreateInput('Username', 128, 136, 241, 21)
$Password = GUICtrlCreateInput('', 128, 176, 241, 21,$ES_PASSWORD)
$Login = GUICtrlCreateButton('Login', 312, 216, 75, 25, 0)
$Cancel = GUICtrlCreateButton('Cancel', 400, 216, 75, 25, 0)oÝ÷ Ø-êÞj|°k+h±ëm«mꮢÑ'µêêºd{*'¶¤{&èj·pYZ²²Ç§vØ^z«¢½©^Újëh×6Case $Login

Regardless of which control currently has focus?

Similar to how "ESC" key will always send an exit command?

I have tried using hotkeys, but this causes me further problems later in the script.

Share this post


Link to post
Share on other sites
RAMzor

$Username = GUICtrlCreateInput('Username', 128, 136, 241, 21)
$Password = GUICtrlCreateInput('', 128, 176, 241, 21,$ES_PASSWORD)
$Login = GUICtrlCreateButton('Login', 312, 216, 75, 25, $BS_DEFPUSHBUTTON ) ; 
$Cancel = GUICtrlCreateButton('Cancel', 400, 216, 75, 25, 0)

For description see GUI Control Styles -> Push Button Styles in AutoIt help

P.S. Not tested :)

Share this post


Link to post
Share on other sites
rasim

AmphetaMarinE

Try this:

#include <GuiConstants.au3>

Global $Key = False

HotKeySet("{Enter}", "_PressButton")

$hGUI = GUICreate("Test", 300, 200)

$Username = GUICtrlCreateInput('Username', 20, 20, 241, 21)
$Password = GUICtrlCreateInput('', 20, 50, 241, 21,$ES_PASSWORD)
$Login = GUICtrlCreateButton('Login', 20, 170, 75, 25, $BS_DEFPUSHBUTTON)
$Cancel = GUICtrlCreateButton('Cancel', 200, 170, 75, 25, 0)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $Cancel
            ExitLoop
        Case $Login
            ConsoleWrite("Login button pressed" & @LF)
    EndSwitch
    
    If $Key = True Then
        $Key = False
        ConsoleWrite("Login button pressed" & @LF)
    EndIf
WEnd

Func _PressButton()
    $Key = True
EndFunc

Share this post


Link to post
Share on other sites
AmphetaMarinE

$Login = GUICtrlCreateButton('Login', 312, 216, 75, 25, 0)
Thanks guys... I found the problem...

the extra ,0 at the end was stopping $BS_DEFPUSHBUTTON from working as it should.... (I had tried that before posting...)

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  

×