Jump to content
Sign in to follow this  

How 2 get blinking cursor position within string?

Recommended Posts

Hi there,

just a short question (search didn't help :) ):

Is there an easy and short way to get the position of the blinking cursor within a textstring?

i.e.: "This is a tE|St sentences" - I need to have the position within the string where (in this example the pipe) the blinking cursor is.

I searched the helpfile, this forum, google, altavista, yahooo and and....

i would like to thank you all, for your always good and patient help i often get. thx :)



Share this post

Link to post
Share on other sites

Have a look in the help file at these functions.



These will give you the current insertion point in Edit and RichEdit controls.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post

Link to post
Share on other sites

@Bowmore: Does this work even there is no Editcontrol available because there is no GUI programmed in AutoIT?

Sorry i forgot to mention what my purpose is. :)

I have a Window inspected with the AutoIT-Info-Tool. So i know all the visible Text.

- In this special case the Window show the whole USBSTOR\pci-ven-id\%usbstickID.

- So i have the whole stringlen.

- i need to ensure that if somebody marked the string NOT completely with the left mousebutton to show immediatly a warning message

(i.e. somebody clicked between "...pci-" and "ven-id...")

hope it's a little bit clearly now.


Share this post

Link to post
Share on other sites

You can try this:

;coded by UEZ 2011
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Caret Position", 232, 93)
$input = GUICtrlCreateInput("", 42, 30, 140)
$label = GUICtrlCreateLabel("Caret Pos: 0", 42, 60, 150)
GUICtrlSetFont(-1, 10)


$dll = DllOpen("user32.dll")
$aCPos = 0
Dim $aString[1]

While Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    If _IsPressed("25", $dll) Or _IsPressed("27", $dll) Then
        $aCPos = GetCaretPos()
        GUICtrlSetData($label, "Caret Pos: " & _ArraySearch($aString, $aCPos[0]))

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    If BitAND($wParam, 0x0000FFFF) = $input Then
        Local $aPos = GetCaretPos()
        If  _ArraySearch($aString, $aPos[0]) = - 1 Then _ArrayAdd($aString,  $aPos[0])
        GUICtrlSetData($label, "Caret Pos: " & _ArraySearch($aString, $aPos[0]))
        Local $len = StringLen(GUICtrlRead($input))
        If $len > 0 Then
            ReDim $aString[$len]
            ReDim $aString[1]
    Return "GUI_RUNDEFMSG"

Func GetCaretPos() ;http://msdn.microsoft.com/en-us/library/ms648402(v=vs.85).aspx
    Local Const $Point = "LONG x;LONG y;"
    Local $sPoint = DllStructCreate($Point)
    DllCall("User32.dll", "int", "GetCaretPos", "ptr", DllStructGetPtr($sPoint))
    Local $aPos[2] = [DllStructGetData($sPoint, "x") - 1, DllStructGetData($sPoint, "y")]
    Return $aPos

It is not bug free but maybe it is going to the right direction.



Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post

Link to post
Share on other sites


WinWaitActive("Untitled - Notepad")

Send("aaaaaaaaaaaaaaaaaaaaaaaa" & @LF _
         & "aaaaaaaaaaaaaaaaaaaaaaaa" & @LF _
         & "aaaaaaaaaaaaaaaaaaaaaaaa" & @LF _
         & "aaaaaaaaaaaaaaaaaaaaaaaa" & @LF _
         & "aaaaaaaaaaaaaaaaaaaaaaaa" & @LF _
         & "aaaaaaaaaaaaaaaaaaaaaaaa")
$line = ControlCommand("[CLASS:Notepad]", "", "Edit1", "GetCurrentLine", "")
$colum = ControlCommand("[CLASS:Notepad]", "", "Edit1", "GetCurrentCol", "")

MsgBox(0, "Return", "curser at line " & $line & @LF & "Position " & $colum)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...