Jump to content

Exit GUI question


McGyver
 Share

Recommended Posts

Ok, this is probably a very easy question. I have a simple script the accepts two inputs and can be closed via the "Login" button.

What I want to be able to do is also allow it to accept hitting "Enter" on the keyboard as well

Local $login, $password, $btn, $msg

GUICreate("Login", 300, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES

GUICtrlCreateLabel("Login", 15, 7)

$login = GUICtrlCreateInput("", 70, 5, 200, 20)

GUICtrlCreateLabel("Password", 15, 32)

$password = GUICtrlCreateInput("", 70, 30, 200, 20)

$btn = GUICtrlCreateButton("Login", 125, 75, 60, 20)

GUISetState()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

ExitLoop

EndSelect

WEnd

Link to comment
Share on other sites

just change your case to

Case $msg = $btn or _ispressed ("0D")

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Here one possibility:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $login, $password, $btn, $msg

GUICreate("Login", 300, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
GUICtrlCreateLabel("Login", 15, 7)
$login = GUICtrlCreateInput("", 70, 5, 200, 20)
GUICtrlCreateLabel("Password", 15, 32)
$password = GUICtrlCreateInput("", 70, 30, 200, 20, $ES_PASSWORD)
$btn = GUICtrlCreateButton("Login", 125, 75, 60, 20)

GUISetState()

$Dummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_COMMAND, "KeyCheck")

$msg = 0
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn, $Dummy, $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIRegisterMsg($WM_COMMAND, "")
GUIDelete()
Exit

Func KeyCheck($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    If Not BitAND($wParam, 0xFFFF0000) And GUICtrlRead($login) <> "" And GUICtrlRead($password) <> "" Then GUICtrlSendToDummy($Dummy)
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Just make your Login button defpushbutton

$btn = GUICtrlCreateButton("Login", 125, 75, 60, 20, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON ))

Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default.

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...