Jump to content
Sign in to follow this  

Input from one control to next without tabbing

Recommended Posts

I have two input controls, first with max 2 characters and second with max 5 characters, as soon as user enters two characters in first input control, I want to move him to next Input control without him hitting the tab, How can I do that ?

Your help is appreciated.

My Code:

$caseyear = GUICtrlCreateInput("", 224, 128, 73, 32, $ES_NUMBER)

GUICtrlSetLimit($caseyear, 2)

$Label3 = GUICtrlCreateLabel("-", 304, 128, 10, 28)

$casenum = GUICtrlCreateInput("", 320, 128, 145, 32, $ES_NUMBER)

GUICtrlSetLimit($casenum, 5)

I want to move to $casenum after I enter two digit for year without hitting TAB key.

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forum. :blink:

You can do what you want like this:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hInput_1 = GUICtrlCreateInput("", 10, 10, 200, 20)
; Set limit for top input
GUICtrlSetLimit(-1, 2)

$hInput_2 = GUICtrlCreateInput("", 10, 50, 200, 20)
; Set limit for bottom input
GUICtrlSetLimit(-1, 5)


; Set focus to top input
GUICtrlSetState($hInput_1, $GUI_FOCUS)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

    ; If bottom input is empty
    If GUICtrlRead($hInput_2) = "" Then
        ; And top input is full
        If StringLen(GUICtrlRead($hInput_1)) = 2 Then
            ; Set focus to bottom input
            GUICtrlSetState($hInput_2, $GUI_FOCUS)


Note that we need 2 checks to decide when we need to set focus to the bottom input - if you remove the outer If statement, it does not work as you want. Try it and see! :P

Please ask if you have any questions. ;)


P.S. If you want a more complicated example - you can look here! :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $iInput_Limit = 2

$hGUI = GUICreate("Demo", 200, 100)

$hInput_1 = GUICtrlCreateInput("", 20, 20, 30, 20)
GUICtrlSetLimit(-1, $iInput_Limit)
$hInput_2 = GUICtrlCreateInput("", 80, 20, 30, 20)
GUICtrlSetLimit(-1, $iInput_Limit)
$hInput_3 = GUICtrlCreateInput("", 140, 20, 30, 20)
GUICtrlSetLimit(-1, $iInput_Limit)

$hButton = GUICtrlCreateButton("OK", 60, 60, 80, 30)
GUICtrlSetState(-1, $GUI_DISABLE)

GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND") ; 0x0111


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $hButton
            $sResult = GUICtrlRead($hInput_1) & "-" & GUICtrlRead($hInput_2) & "-" & GUICtrlRead($hInput_3)
            MsgBox(0, "You have entered", $sResult)

    ; Enable button when last input filled
    If StringLen(GUICtrlRead($hInput_3)) = 2 And BitAnd(GUICtrlGetState($hButton), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($hButton, $GUI_ENABLE)


Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    $nNotifyCode = BitShift($wParam, 16)
    $iControlID = BitAnd($wParam, 0x0000FFFF)
    ; If input filled move focus to next
    Switch $nNotifyCode
        Case 0x400 ;$EN_UPDATE
            If StringLen(GUICtrlRead($iControlID)) = $iInput_Limit Then GUICtrlSetState($iControlID + 1, $GUI_FOCUS)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


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