Jump to content

GuiCtrlCreateInput automatically hit Enter


Go to solution Solved by MyEarth,

Recommended Posts

I currently have an inputbox that only accepts numbers and only accepts 4 characters.  When they are finished typing in those numbers, you hit enter and it will call a function.  How can i make it so it automatically calls my function after they type 4 numbers into that box (instead of requiring an ENTER push)?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

$Form1_1 = GUICreate("test")
$Input1 = GUICtrlCreateInput("", 72, 16, 136, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
GUICtrlSetLimit($Input1, 4, 4)
GUISetState(@SW_SHOW)
$ButtonDummy = GUICtrlCreateDummy()
Dim $EnterArray[1][2] = [["{ENTER}", $ButtonDummy]]
GUISetAccelerators($EnterArray)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonDummy
            Enter()
    EndSwitch
WEnd

Func Enter()
    MsgBox(0,"","Enter pressed")
EndFunc
Edited by hiimjoey11
Link to comment
Share on other sites

  • Solution

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $Flag = True ; declare a flag

$Form1_1 = GUICreate("test")
$Input1 = GUICtrlCreateInput("", 72, 16, 136, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
GUICtrlSetLimit($Input1, 4, 4)
GUISetState(@SW_SHOW)
$ButtonDummy = GUICtrlCreateDummy()
Local $EnterArray[1][2] = [["{ENTER}", $ButtonDummy]] ; Dim is deprecated
GUISetAccelerators($EnterArray)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonDummy
            Enter()
    EndSwitch
    If StringLen(GUICtrlRead($Input1)) = 4 And $Flag Then ; check if the value and the flag
        $Flag = False
        GUICtrlSendToDummy($ButtonDummy) ; send enter
    ElseIf StringLen(GUICtrlRead($Input1)) <= 3 And Not $Flag Then ; if not clear the flag
        $Flag = True
    EndIf
WEnd

Func Enter()
    MsgBox(0, "", "Enter pressed")
EndFunc   ;==>Enter

I prefer WM_COMMAND but for a new autoit user that was an easy way

Link to comment
Share on other sites

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $Flag = True ; declare a flag

$Form1_1 = GUICreate("test")
$Input1 = GUICtrlCreateInput("", 72, 16, 136, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
GUICtrlSetLimit($Input1, 4, 4)
GUISetState(@SW_SHOW)
$ButtonDummy = GUICtrlCreateDummy()
Local $EnterArray[1][2] = [["{ENTER}", $ButtonDummy]] ; Dim is deprecated
GUISetAccelerators($EnterArray)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonDummy
            Enter()
    EndSwitch
    If StringLen(GUICtrlRead($Input1)) = 4 And $Flag Then ; check if the value and the flag
        $Flag = False
        GUICtrlSendToDummy($ButtonDummy) ; send enter
    ElseIf StringLen(GUICtrlRead($Input1)) <= 3 And Not $Flag Then ; if not clear the flag
        $Flag = True
    EndIf
WEnd

Func Enter()
    MsgBox(0, "", "Enter pressed")
EndFunc   ;==>Enter

I prefer WM_COMMAND but for a new autoit user that was an easy way

 

Works perfect thank you :)

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