Getting the cursors position

I’m working on my own chatbox, however I’m having some issues trying to figure out where to place the cursor (the blinking line thing). It’s easy to just put it at the end of what the users typing, but I’m not sure how to go about controlling its movement with the arrow keys. The only idea I could think of was using **[Input.IsKeyDown](**, so if the right arrow key is down, move the cursor 1 character right every x frames/seconds. This seems a bit hacky though, I was wondering if there was an easier way to do it.

(Note, I’m not trying to move the point where the text is inserted, GMod seems to do that for me, I just need to move the cursor to match up with it.)


Cursor probably wasn’t the best word to describe it, but I don’t know it’s technical name.

It’s actually called the cursor.

Also, couldn’t you use DTextEntry instead? It has the cursor with it and you can actually highlight stuff ( or atleast see what is highlighted. )

Maybe you could use surface.Setfont and surface.GetTextSize to find the length of your text.
Then when you move your cursor you add or take 1 from a certain variable.
And using string.sub you could find out where that letter ends.

For example, your text is 5 letters long.
Then when you hit the left arrow key you change a certain variable to 4, and find out what the text size is of letters 1 to 4 and place your cursor accordingly.

But then surely if someone held the button down it’d move more than one and end up out of sync.

Just had an idea, would it be possible to force the player to press a key (for example “a”), detect where in the string it’s added and then use that as the position? Or is that even more hacky than it’s worth?


It’s actually called a caret. Drake, do you need this for making your own TextEntry.Paint function? If so, call **[DTextEntry.DrawTextEntryText](** at the end of your function. If not, I would consider switching to a TextEntry instead of (what I assume you are doing, which is) drawing the text from ChatTextChanged yourself.

Thank you, I was just drawing the text from ChatTextChanged yeah, I’ll change it.