Jump to content

Enter key in Input triggers Button


easypic
 Share

Recommended Posts

Hey Guys, i'm pretty new to this so i'm playing around alot, i've tried searching the forums but cannot find anything.

I am trying to create a simple login GUI.

My Question is can i write in the script that if i press ENTER whilst on an Input Box, the script will press the "Sign In" Button????

I'm using oneventmode

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Sign In", 322, 133, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Pic1 = GUICtrlCreatePic("", 8, 16, 129, 105, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("Username:", 144, 24, 55, 17)
$Label2 = GUICtrlCreateLabel("Password", 144, 56, 50, 17)
$Input1 = GUICtrlCreateInput("", 200, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 200, 56, 121, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Sign In", 240, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1, 512)
$Button2 = GUICtrlCreateButton("Create...", 144, 88, 75, 25, 0)
GUICtrlSetOnEvent(-1, "Create_New")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Opt("GUIOnEventMode", 1)
While 1
    Sleep (10)
WEnd



Func Create_New()
$createUser = InputBox("Create new Account", "Please type your Username")
$checkUser = IniRead(@ScriptDir & "\user.ini", $createUser, "Username", 0)
If $createUser = $checkUser Then
    MsgBox(0, "User Already Exists", "User Already Exists")
Else
IniWrite(@ScriptDir & "\user.ini", $createUser, "Username", $createUser)
$createUserPass = InputBox("Create ne Account", "Enter Password", "", " M")
IniWrite(@ScriptDir & "\user.ini", $createUser, "Password", $createUserPass)
EndIf
EndFunc

Func Login()
$test = GUICtrlRead($Input1)
$test1 = GUICtrlRead($Input2)
$Usernamecheck = IniRead(@ScriptDir & "\user.ini", $test, "Username", 0)
$passwordcheck = IniRead(@ScriptDir & "\user.ini", $test, "Password", 0)
If $test = $Usernamecheck Then
    TrayTip("Logging In", "", 1)
EndIf
If $test1 = $passwordcheck Then
    MsgBox(0, "Login Success", "Login Successful!")
Else
    MsgBox(0, "Incorrect", "Incorrect Username / Password")
EndIf

EndFunc



Func CLOSEClicked ()
If @GUI_WinHandle = $Form1 Then
    Exit
EndIf
EndFunc
Link to comment
Share on other sites

Hey Alek

Thanks heaps, i tried it and it created a highlight around the button but when i press enter nothing happens.

A small correction to the above code it's meant to be

Am i doint something wrong?

That is correct but GUICtrlSetOnEvent(-1, 512 was not.)

Add the same line after the GuiCtrlCreatEdit lines and they will also call "Login" when you press Enter. Or you could have the name input call a different function on Enter pressed which made the focus move to the password input.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...