How to place text cursor?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stevethaw7
Posts: 9
Joined: 08 Feb 2018, 09:46

How to place text cursor?

08 Feb 2018, 15:32

I need some help in placing the text cursor.

Here's the situation:
- Open a text file.
- Copy the text to the Clipboard.
- Use InStr to find the position of a specified text string.
- Next I need to position the text cursor (not the mouse cursor) at the beginning of the specified text string. How does one do that?

Thanks.

Steve
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to place text cursor?

08 Feb 2018, 15:57

You could do it by sending the left arrow key once while the text is still selected to un-select it and move the caret to the start of the line, then sending the right arrow key a number of times equal to the position that you retrieved with InStr.
Last edited by Osprey on 08 Feb 2018, 16:25, edited 1 time in total.
stevethaw7
Posts: 9
Joined: 08 Feb 2018, 09:46

Re: How to place text cursor?

08 Feb 2018, 16:20

Thank you. I tried that and it will work. However, the text file is several thousand characters in length. Right-arrowing far into the document takes a relatively long time, not a good experience for the user to sit there and watch and wait. I was hoping there is a more direct, efficient way to place the cursor.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to place text cursor?

08 Feb 2018, 16:31

You could automate the Find dialog, if the text viewer supports it... something like:

Code: Select all

Send, ^{home}^f  ; Ctrl+Home moves the caret to the start of the document. Ctrl+F opens the Find dialog.
WinWait, Find
Send, Text string to find{enter}{esc}^{left}  ; Enter begins the search. Esc closes the Find dialog. Ctrl+Left moves the caret to the start of the selection.
That works in Notepad.
stevethaw7
Posts: 9
Joined: 08 Feb 2018, 09:46

Re: How to place text cursor?

08 Feb 2018, 20:34

The text viewer does have a find function and it appears to work as expected. I will go that route.

Thank you Osprey :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: joedf, OrangeCat, scriptor2016, supplementfacts and 134 guests