Jump to content

Getting input char count in real time


Recommended Posts

Hi all,

Is there a way in AutoIt to count input characters are they are coming into either a GUI or InputBox? This is different than just using StringLen because that depends on the InputBox being already submitted. I want to be able to trigger an action when the input reaches X characters.

Thanks.

Link to comment
Share on other sites

Here's one way I do it

While 1
    $msg = GUIGetMsg()
    $name = GUICtrlRead($namebox)
    $len=StringLen($name)
    If $len > 13 Then ;if length is greater than 13
        GUICtrlSetData($namebox,StringLeft($name,13));only place first 13 characters
        ;or whatever code you want
    EndIf
    Select
        Case $msg = $ok
            ;stuff
        Case $msg = $cancel
            ;stuff
    EndSelect
WEnd

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Try this

#include <GUIConstantsEx.au3>

$_Gui = GUICreate ( "", 300, 150, 200, 150 )
$_Input1 = GUICtrlCreateInput ( "blah-blah", 50, 35, 200, 20 )
$_Button1 = GUICtrlCreateButton ( "Button1", 50, 100, 80, 20 )
GUISetState ( )
$_StringLenOld=0

While 1
    $_Msg = GUIGetMsg ( )
    Switch $_Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $_Button1

    EndSwitch
    $_CursorInfo = GUIGetCursorInfo ( $_Gui )
    If $_CursorInfo[2] And $_CursorInfo[4] = $_Input1 Then GUICtrlSetData ( $_Input1, "" )

    $_StringLen = StringLen ( GUICtrlRead ( $_Input1 ) )
    If $_StringLen <> $_StringLenOld Then
        ConsoleWrite ( "-->-- $_StringLen : " & $_StringLen & @Crlf )
        $_StringLenOld = $_StringLen
    EndIf
WEnd

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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