Jump to content

Auto tab @ charlimit


RagnaroktA
 Share

Recommended Posts

How would I go about having a GUI automatically tab to the next object when a character limit is reached?

ex. IP Address

$IPAddress1 = GUICtrlCreateInput("", 110, 270, 30, 20)
GUICtrlSetLimit($IPAddress1, 3, 1)
$IPAddress2 = GUICtrlCreateInput("", 110, 270, 30, 20)
GUICtrlSetLimit($IPAddress1, 3, 1)

In the code, the limit for the inputs is 3 chars. When that limit is reached, how do you set it to automatically tab to the next input?

Edited by RagnaroktA
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $IPAddress[2]

$IPAddress[0] = GUICtrlCreateInput("", 110, 270, 30, 20)
GUICtrlSetLimit($IPAddress[0], 3, 1)
$IPAddress[1] = GUICtrlCreateInput("", 150, 270, 30, 20)
GUICtrlSetLimit($IPAddress[1], 3, 1)

$nCurEdit = 0
GuiSetState()
While 1
    $msg = GuiGetMsg()
    $ip = _IsPressedMod()
    If $ip > 0 Then
        $ip_tmp = GUICtrlRead($IPAddress[$nCurEdit])
        If (StringLen($ip_tmp) = 3) And not ($ip = 8) Then
            If $nCurEdit = UBound($IPAddress) - 1 Then ContinueLoop
            $nCurEdit = $nCurEdit + 1
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
        ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then
            If $nCurEdit = 0 Then ContinueLoop
            $nCurEdit = $nCurEdit - 1
            Sleep ( 200 ); make sure buffer clears
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($IPAddress[$nCurEdit], GUICtrlRead($IPAddress[$nCurEdit]))
        EndIf
    EndIf
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit

Func _IsPressedMod()
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 128
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc  ;==>_IsPressedMod

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $IPAddress[2]

$IPAddress[0] = GUICtrlCreateInput("", 110, 270, 30, 20)
GUICtrlSetLimit($IPAddress[0], 3, 1)
$IPAddress[1] = GUICtrlCreateInput("", 150, 270, 30, 20)
GUICtrlSetLimit($IPAddress[1], 3, 1)

$nCurEdit = 0
GuiSetState()
While 1
    $msg = GuiGetMsg()
    $ip = _IsPressedMod()
    If $ip > 0 Then
        $ip_tmp = GUICtrlRead($IPAddress[$nCurEdit])
        If (StringLen($ip_tmp) = 3) And not ($ip = 8) Then
            If $nCurEdit = UBound($IPAddress) - 1 Then ContinueLoop
            $nCurEdit = $nCurEdit + 1
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
        ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then
            If $nCurEdit = 0 Then ContinueLoop
            $nCurEdit = $nCurEdit - 1
            Sleep ( 200 ); make sure buffer clears
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($IPAddress[$nCurEdit], GUICtrlRead($IPAddress[$nCurEdit]))
        EndIf
    EndIf
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit

Func _IsPressedMod()
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 128
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc  ;==>_IsPressedMod
It worked, thanks! One more small addition... when the period key is pressed, I'd like it to tab as well. How would I go about doing that? I would also like to keep the string numeric... and not allow letters or other chars. Just 0-9... Edited by RagnaroktA
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $IPAddress[2]

$IPAddress[0] = GUICtrlCreateInput("", 110, 270, 30, 20,$ES_NUMBER)
GUICtrlSetLimit($IPAddress[0], 3, 1)
$IPAddress[1] = GUICtrlCreateInput("", 150, 270, 30, 20,$ES_NUMBER)
GUICtrlSetLimit($IPAddress[1], 3, 1)

$nCurEdit = 0
GuiSetState()
While 1
    $msg = GuiGetMsg()
    $ip = _IsPressedMod()
    If $ip > 0 Then
        $ip_tmp = GUICtrlRead($IPAddress[$nCurEdit])
        If ((StringLen($ip_tmp) = 3) And not ($ip = 8)) Or $ip = 190 Then
            If $nCurEdit = UBound($IPAddress) - 1 Then ContinueLoop
            $nCurEdit = $nCurEdit + 1
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
        ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then
            If $nCurEdit = 0 Then ContinueLoop
            $nCurEdit = $nCurEdit - 1
            Sleep ( 200 ); make sure buffer clears
            GUICtrlSetState($IPAddress[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($IPAddress[$nCurEdit], GUICtrlRead($IPAddress[$nCurEdit]))
        EndIf
    EndIf
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit

Func _IsPressedMod()
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 256
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc  ;==>_IsPressedMod

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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