Palestinian Posted January 31, 2014 Share Posted January 31, 2014 Hello everyone. I'm trying to make a GUI input box where once the max number of characters is entered a "TAB" action is triggered so the input focus would switch to the next input box, I tried searching both Google and the forums for an answer but failed to find any, the closest thing I found was this I figured the code posted in the 1st post might actually do the trick, tried it but it did nothing, maybe I was misplacing it in my script.. In theory that code should work, but I just can't seem to find the right place to put it, and from my simple understanding of GUI's, there is no constant check on whats going on with the GUI once you run the script unless you write a code to do a check, but then again, during my search on other issues I learned that Autoit doesn't do multithreading, meaning I can't get the GUI to check for changes in order to trigger the "TAB" action while the script is doing something else, right? Any help will be much appreciated Link to comment Share on other sites More sharing options...
Solution BrewManNH Posted January 31, 2014 Solution Share Posted January 31, 2014 I found this code >here and updated it to be usable in the latest version of Autoit. #include <GUIConstants.au3> #include <GUIEdit.au3> GuiCreate("Enter Registration Code",300,50,@DesktopWidth/2-150,@DesktopHeight/2-25) $i1 = GuiCtrlCreateInput("",10,15,50,20) GuiCtrlSetLimit($i1,5) $i2 = GuiCtrlCreateInput("",70,15,50,20) GuiCtrlSetLimit($i2,5) $i3 = GuiCtrlCreateInput("",130,15,50,20) GuiCtrlSetLimit($i3,5) $b1 = GuiCtrlCreateButton("Next >",190,15,50,20) $b2 = GuiCtrlCreateButton("Exit",250,15,40,20) GuiSetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE or $msg = $b2 ExitLoop Case $msg = $b1 MsgBox(0,"Next","This button gets the focus when the last input box is filled.") EndSelect If _GUICtrlEdit_LineLength($i1) = 5 and _GUICtrlEdit_GetModify($i1) > 0 Then GuiCtrlSetState($i2,$GUI_FOCUS) _GUICtrlEdit_SetModify($i1,false) EndIf If _GUICtrlEdit_LineLength($i2) = 5 and _GUICtrlEdit_GetModify($i2) > 0 Then GuiCtrlSetState($i3,$GUI_FOCUS) _GUICtrlEdit_SetModify($i2,false) EndIf If _GUICtrlEdit_LineLength($i3) = 5 and _GUICtrlEdit_GetModify($i3) > 0 Then GuiCtrlSetState($b1,$GUI_FOCUS) _GUICtrlEdit_SetModify($i3,false) EndIf WEnd Should do what you need, or at least get you started. Palestinian 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
BlackDawn187 Posted January 31, 2014 Share Posted January 31, 2014 (edited) In your situation, I would "count" key strokes. Count the number of keys pressed. Then, Send("{TAB}"), When $KeysCounted >= $MaxNumber. Otherwise, You can use BrewMans example. For reasons pertaining to the forum rules, I won't elaborate further on how to do so. But, It seems like the best solution in my opinion. Edited January 31, 2014 by BlackDawn187 Link to comment Share on other sites More sharing options...
Palestinian Posted January 31, 2014 Author Share Posted January 31, 2014 I found this code >here and updated it to be usable in the latest version of Autoit. #include <GUIConstants.au3> #include <GUIEdit.au3> GuiCreate("Enter Registration Code",300,50,@DesktopWidth/2-150,@DesktopHeight/2-25) $i1 = GuiCtrlCreateInput("",10,15,50,20) GuiCtrlSetLimit($i1,5) $i2 = GuiCtrlCreateInput("",70,15,50,20) GuiCtrlSetLimit($i2,5) $i3 = GuiCtrlCreateInput("",130,15,50,20) GuiCtrlSetLimit($i3,5) $b1 = GuiCtrlCreateButton("Next >",190,15,50,20) $b2 = GuiCtrlCreateButton("Exit",250,15,40,20) GuiSetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE or $msg = $b2 ExitLoop Case $msg = $b1 MsgBox(0,"Next","This button gets the focus when the last input box is filled.") EndSelect If _GUICtrlEdit_LineLength($i1) = 5 and _GUICtrlEdit_GetModify($i1) > 0 Then GuiCtrlSetState($i2,$GUI_FOCUS) _GUICtrlEdit_SetModify($i1,false) EndIf If _GUICtrlEdit_LineLength($i2) = 5 and _GUICtrlEdit_GetModify($i2) > 0 Then GuiCtrlSetState($i3,$GUI_FOCUS) _GUICtrlEdit_SetModify($i2,false) EndIf If _GUICtrlEdit_LineLength($i3) = 5 and _GUICtrlEdit_GetModify($i3) > 0 Then GuiCtrlSetState($b1,$GUI_FOCUS) _GUICtrlEdit_SetModify($i3,false) EndIf WEnd Should do what you need, or at least get you started. It did precisely what I needed, used one of the If statements and it worked like a charm, thanks a lot mate, I really appreciate it! In your situation, I would "count" key strokes. Count the number of keys pressed. Then, Send("{TAB}"), When $KeysCounted >= $MaxNumber. Otherwise, You can use BrewMans example. For reasons pertaining to the forum rules, I won't elaborate further on how to do so. But, It seems like the best solution in my opinion. Wouldn't the key strokes count be effected by the over all key strokes on the GUI? Link to comment Share on other sites More sharing options...
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