Jump to content

Auto advancing edit field


KXM
 Share

Recommended Posts

Is there a way to have an edit field automaticly advance after x amount of chars (and 'devance' on backspace) like in the key entry feilds of program installers?

If so any tips or pointers would be greatly welcomed.

TIA.

Link to comment
Share on other sites

THIS IS MERELY PSEUDOCODE. IT WILL BE WRONG AS A SCRIPT AS IS

$msg = GUIGetMsg()
    Select
      Case ($msg = $QuitBtn) OR ($msg = $GUI_EVENT_CLOSE)
        QuitBtnClick()
 
      Case $msg = $SpareBtn
        SpareBtnClick()
      Case $msg = $SubmitBtn
        IF CodeIsValid ($SecCode) THEN
                                    ;Exit This Loop
  Case $msg = $SecCode1
    $SecCodePart1 = String(GUICtrlRead($SecCode1))
    If StringLen($SecCodePart1) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode2)

  Case $msg = $SecCode2
    $SecCodePart2 = String(GUICtrlRead($SecCode2))
    If StringLen($SecCodePart2) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode3)

;etc.


  Case $msg = $SecCode5;LAST EDIT BOX
    $SecCodePart5 = String(GUICtrlRead($SecCode5))
    If StringLen($SecCodePart5) = $ValidLen Then
$SecCode = String(GUICtrlRead($SecCode1)) & String(GUICtrlRead($SecCode2)) ;etc.

    EndSelect

J

Edited by jdickens

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

First, and foremost, thanks!

I tried what you suggusted (in autoit friedly code) but for reasions I can't understand the case loop dosen't seem to reconize when the second control if foucsed

IE:

$validlen = 4

Case $msg = $SecCode1
    $SecCodePart1 = String(GUICtrlRead($SecCode1))
    If StringLen($SecCodePart1) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode2)

Case $msg = $SecCode2
    $SecCodePart2 = String(GUICtrlRead($SecCode2))
    If StringLen($SecCodePart2) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode3)

Will focus control 2 on success, but will not do the same for contel 2 to 3.

i've tried variations on the coder including some contenueloop and msgboxs. And I've concluded the the sceond control's case isn't being reconized.

IE:

$validlne = 4

Case $msg = $SecCode1
    $SecCodePart1 = String(GUICtrlRead($SecCode1))
    If StringLen($SecCodePart1) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode2)

Case $msg = $SecCode2
    MsgBox(0,"","Control 2 case started")
    $SecCodePart2 = String(GUICtrlRead($SecCode2))
    If StringLen($SecCodePart2) = $ValidLen Then
ControlFocus($MyGUITitle, "", $SecCode3)

Will not show a message box.

Any ideas?

Edited by KXM
Link to comment
Share on other sites

I'm trying to solve this, here results. Probably need some tweaks but basically works.

#include <GUIConstants.au3>

Dim $ahEdit[3] 

$hGUI = GUICreate("Window Title",260,250)
$ahEdit[0] = GUICtrlCreateInput("", 5, 5, 40, 20)
GUICtrlSetLimit (-1, 5)
$ahEdit[1] = GUICtrlCreateInput("", 50, 5, 40, 20)
GUICtrlSetLimit (-1, 5)
$ahEdit[2] = GUICtrlCreateInput("", 95, 5, 40, 20)
GUICtrlSetLimit (-1, 5)

$nCurEdit = 0

GUISetState()

While 1
    $ip = _IsPressedMod()
    If $ip > 0 Then
        $res = GUICtrlRead($ahEdit[$nCurEdit])
        If (StringLen($res) = 5) and not ($ip = 8) Then 
            If $nCurEdit = UBound($ahEdit) - 1 Then ContinueLoop
            $nCurEdit = $nCurEdit + 1
            GUICtrlSetState($ahEdit[$nCurEdit], $GUI_FOCUS)
            ContinueLoop
        Endif
        If (StringLen($res) = 0) and ($ip = 8) Then
            If $nCurEdit = 0 Then ContinueLoop
            $nCurEdit = $nCurEdit - 1
            GUICtrlSetState($ahEdit[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($ahEdit[$nCurEdit], GUICtrlRead($ahEdit[$nCurEdit])); Stupid trick but works
            ContinueLoop
        Endif
    Endif
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd


Func _IsPressedMod()
  Local $aR, $bRv
  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
Link to comment
Share on other sites

  • 4 weeks later...

Hi !

Few keys are not "view" by the code :  ²  )  =  ù  etc.

I use a keyboard AZERTY  (french)

Is it normal ?

<{POST_SNAPBACK}>

Re

I have found. It's ok with :

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

(128 --> 255)

Good night !

Link to comment
Share on other sites

  • 2 weeks later...

I'm trying to solve this, here results. Probably need some tweaks but basically works.

#include <GUIConstants.au3>

Dim $ahEdit[3] 

$hGUI = GUICreate("Window Title",260,250)
$ahEdit[0] = GUICtrlCreateInput("", 5, 5, 40, 20)
GUICtrlSetLimit (-1, 5)
$ahEdit[1] = GUICtrlCreateInput("", 50, 5, 40, 20)
GUICtrlSetLimit (-1, 5)
$ahEdit[2] = GUICtrlCreateInput("", 95, 5, 40, 20)
GUICtrlSetLimit (-1, 5)

$nCurEdit = 0

GUISetState()

While 1
    $ip = _IsPressedMod()
    If $ip > 0 Then
        $res = GUICtrlRead($ahEdit[$nCurEdit])
        If (StringLen($res) = 5) and not ($ip = 8) Then 
            If $nCurEdit = UBound($ahEdit) - 1 Then ContinueLoop
            $nCurEdit = $nCurEdit + 1
            GUICtrlSetState($ahEdit[$nCurEdit], $GUI_FOCUS)
            ContinueLoop
        Endif
        If (StringLen($res) = 0) and ($ip = 8) Then
            If $nCurEdit = 0 Then ContinueLoop
            $nCurEdit = $nCurEdit - 1
            GUICtrlSetState($ahEdit[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($ahEdit[$nCurEdit], GUICtrlRead($ahEdit[$nCurEdit])); Stupid trick but works
            ContinueLoop
        Endif
    Endif
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Func _IsPressedMod()
  Local $aR, $bRv
  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

<{POST_SNAPBACK}>

i'm sorry but i'm having a horrid time trying to figure out wtf is going on with this.

I guess to start off with what does the _IsPressedMod function do? I understand that the two if loops are what actually advance the fous forward and back but i'm not sure how any of that is determined

thx for help

PS i'm trying to make a phone number entry for a gui of mine and not all of the fields would have the same number of chars. ie they will be 3-3-4 and 2-2-2-4 (number of chars in each input)

Link to comment
Share on other sites

I guess to start off with what does the _IsPressedMod function do? I understand that the two if loops are what actually advance the fous forward and back but i'm not sure how any of that is determined

This checks if one of keys with scancode from 8 to 128 is pressed (you can use all range from 0 to 255, but this is redundant imo), and in this case return pressed key code. It's used for determine that something changed in the field and for checking if backspace is pressed.

PS i'm trying to make a phone number entry for a gui of mine and not all of the fields would have the same number of chars. ie they will be 3-3-4 and 2-2-2-4 (number of chars in each input)

I use StringLen($res) = 5 for checking fixed length (5), but in your case you can make array with the field lengths (or use additional dimension in the $ahEdit for keep this) and compare length with it's values.

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