Jump to content
Sign in to follow this  

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

Recommended Posts

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


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)


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

Func _PressButton()
    $Key = True

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...