Sign in to follow this  
Followers 0
totaln00ber

Assign Enter key to input boxes

7 posts in this topic

Hey experts,

Trying to assign the enter key to different inputs/textboxes so that when the enter key is pressed on a specific textbox, it runs one function. Pressing the enter key on another textbox it goes to another function. I don't want the user to have to click a submit button or tab to it and press enter.

Didn't find anything under the help files under "Edit/Input Styles", the closest thing was $ES_WANTRETURN

Any suggestions? Thanks!

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

GUICreate('Inputs', 140, 100)

$input1 = GUICtrlCreateInput('', 10, 10, 120, 20)
$input2 = GUICtrlCreateInput('', 10, 40, 120, 20)
$input3 = GUICtrlCreateInput('', 10, 70, 120, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input1
            MsgBox(0, '', GUICtrlRead($input1))
        Case $input2
            MsgBox(0, '', GUICtrlRead($input2))
        Case $input3
            MsgBox(0, '', GUICtrlRead($input3))
    EndSwitch
WEnd

; If you have default text in the input it doesn't work until it's changed.
; If text is highlighted, it won't work.
; If it's the default text, it needs to be unhighlighted AND changed.
; Maybe someone can explain what I'm doing wrong to cause the above.

Share this post


Link to post
Share on other sites

Hmmm, that's a good start. But when you type something into the first textbox and then press TAB to go to the next one, it runs the function as well.

So it looks like the GUIGetMsg() listens for the TAB key as well; can it be disable and just listen for the ENTER key?

Share this post


Link to post
Share on other sites

Hmmm, that's a good start. But when you type something into the first textbox and then press TAB to go to the next one, it runs the function as well.

So it looks like the GUIGetMsg() listens for the TAB key as well; can it be disable and just listen for the ENTER key?

Case $input AND _IsPressed ???

Share this post


Link to post
Share on other sites

Case $input AND _IsPressed ???

#include <GUIConstants.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

GUICreate('Inputs', 140, 100)

$input1 = GUICtrlCreateInput('', 10, 10, 120, 20)
$input2 = GUICtrlCreateInput('', 10, 40, 120, 20)
$input3 = GUICtrlCreateInput('', 10, 70, 120, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input1
            If _IsPressed("0D", $dll) Then
                MsgBox(0, '', GUICtrlRead($input1))
            EndIf
        Case $input2
            If _IsPressed("0D", $dll) Then
                MsgBox(0, '', GUICtrlRead($input2))
            EndIf
        Case $input3
            If _IsPressed("0D", $dll) Then
                MsgBox(0, '', GUICtrlRead($input3))
            EndIf
    EndSwitch
WEnd

Didn't work; not sure if the code structure is correct though.

Share this post


Link to post
Share on other sites

Hmm that tab thing is kind of strange. I guess input sends a message when it's focused with tab. Anyway, you could try this:

#include <GUIConstants.au3>
#include <Misc.au3>

GUICreate('Inputs', 140, 100)

$input1 = GUICtrlCreateInput('', 10, 10, 120, 20)
$input2 = GUICtrlCreateInput('', 10, 40, 120, 20)
$input3 = GUICtrlCreateInput('', 10, 70, 120, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input1
            If Not _IsPressed('09') Then MsgBox(0, '', GUICtrlRead($input1))
        Case $input2
            If Not _IsPressed('09') Then MsgBox(0, '', GUICtrlRead($input2))
        Case $input3
            If Not _IsPressed('09') Then MsgBox(0, '', GUICtrlRead($input3))
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include <Misc.au3>

$hWndGUI = GUICreate('Inputs', 140, 100)

$input1 = GUICtrlCreateInput('', 10, 10, 120, 20)
$input2 = GUICtrlCreateInput('', 10, 40, 120, 20)
$input3 = GUICtrlCreateInput('', 10, 70, 120, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If _IsPressed('0D') Then
        Switch ControlGetFocus($hWndGUI)
            Case 'Edit1'
                MsgBox(0, '$input1', GUICtrlRead($input1))
            Case 'Edit2'
                MsgBox(0, '$input2', GUICtrlRead($input2))
            Case 'Edit3'
                MsgBox(0, '$input3', GUICtrlRead($input3))
        EndSwitch
        Sleep(250)
    EndIf
WEnd


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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