CursorPosition - Forum

Forum Navigation
You need to log in to create posts and topics.

CursorPosition

Hello,

With the command GetObjectInfo we can obtain in a variable the cursor position in a text entry field.

According to you, is it possible with another command or another script, move the cursor to an another part of the text entry?

Thanks for your help.

@feli

Good time!

You can use the SetMousePos command.

Thanks Vadim

But i talk about the cursor into a textentry field...

 

So what you want to do is:
Have here is a text field   [----------]
Is there any text to be pre-filled into the text field like this [text------] ?
And where does the cursor get positioned [text|-----] at the end of the text or [|text-----] begining or somewhere else [text--|---] ?

My object TextEntry contain various lines.

I would like to use a command to force the cursor to go to the start of line 2 or 4 or 6...

 

@feli

You can try using the howSendKeys plugin.

StrLen "[TextEntry1]" "[StrLen]"
GetObjectInfo "TextEntry1" "CursorPosition" "[CursorPosition]"

FocusObject "TextEntry1"

If "[TextEntry2]" ">" "[CursorPosition]"
    SetVar "[Result]" "[NewCursorPosition]-[CursorPosition]-1"
    hpwSendKeysToHandle "[WinHandle]" "{Right [Result]}"
Else
    SetVar "[Result]" "[CursorPosition]-[NewCursorPosition]"
    hpwSendKeysToHandle "[WinHandle]" "{Left [Result]}"
EndIf

GetObjectInfo "TextEntry1" "CursorPosition" "[CursorPosition]"

But there is a problem. You need to take into account the number of lines. Because when counting characters, line breaks are also counted. #13#10 or only #13. This also needs to be foreseen.

Or you can use the EditorsToolbox plugin. I think it can move the cursor to the right place, but it has its own text object. There are some other plugins for working with text. I can't remember them right now.

And yes, the code needs some work. This is just an example. You will have to calculate all the calculations and possible situations yourself. I just sketched out one of the possible options.

TYVM Mishem.

I'll work on that.

I'll keep you posted.

 

@feli

If you just need to move the cursor to the beginning of a specific line, then it's much easier.

StrLen "[TextEntry1]" "[StrLen]"
GetObjectInfo "TextEntry1" "CursorPosition" "[CursorPosition]"
FocusObject "TextEntry1"

While "[CursorPosition]" "<>" "1"
    hpwSendKeysToHandle "[WinHandle]" "{Home}{Up}"
    GetObjectInfo "TextEntry1" "CursorPosition" "[CursorPosition]"
EndWhile

SetVar "[Result]" "[NewCursorPosition]-1"
If "[Result]" ">" "0"
    hpwSendKeysToHandle "[WinHandle]" "{Down [Result]}"
EndIf

GetObjectInfo "TextEntry1" "CursorPosition" "[CursorPosition]"

 

 

I've been trying to modify this cript to no avail.

No matter whet happens, its sends the cursor back to home.

I would like it to return to the beginning or the end of a ligne '[x]'.

@feli

Show your script.

 

In the [NewCursorPosition] variable, you need to specify the line number you want to go to.
This is not a physical line number, but the one that is displayed in the text field. That is, if, for example, your first line is longer than the text field, it will be transferred to a new line, but the characters #13#10 will only be at the end of the line itself. Thus, depending on the size of the text field, font size and text size, your lines may differ from the user's lines.

I don't know your tasks, but it seems to me that it is better to use the Editor's Toolbox v1.75 or Neoeditor plugin.

Well,

mishem, with your help and a lot of research and fine-tunning your example and other related scripys, i've managed to achieve my goal.

Everything workd perfectly for me.

Thank you very much!

Feli