hiimjoey11 Posted December 10, 2014 Posted December 10, 2014 (edited) 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 December 10, 2014 by hiimjoey11
Solution MyEarth Posted December 10, 2014 Solution Posted December 10, 2014 #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
hiimjoey11 Posted December 10, 2014 Author Posted December 10, 2014 #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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now