Get caret position from text input

Hello, is there any function to get caret position from text input ? I found on other threads, that its maybe event.source.getCaretPosition() but ignition is telling me event.source “object has no attribute ‘source’”

Little bit of background I am building Virtual keyboard which will loke like built in keyboard on tablets. So I need to move caret left and right use delete and backspace. Any help ? Thanks in advance.

Can you edit your question to add the Perspective or Vision tag as appropriate?

Meanwhile, there’s a Using Touch Screen Mode - Ignition User Manual 8.1 - Ignition Documentation built into Ignition.

Also give some more detail on where you are trying to call .getCaretPosition(), a text intput event handler for example.
If you are using Vision, you would need to use an event handler of your text input to use event.source.getCaretPosition(). You could create a custom property on the text input and write to it through your event handler(s), then reference the custom property in your back space/delete buttons scripts.

I created quick test, where in which the caret position was retrieved on a mouse or key press event and saved to a custom property “position.” This code worked for the back space button:

position = event.source.parent.getComponent('Text Field').position
if position > 0:
	txt = event.source.parent.getComponent('Text Field').text
	event.source.parent.getComponent('Text Field').text = txt[:position-1] + txt[position:]
	event.source.parent.getComponent('Text Field').position = position -1

I don’t know why but the key press event only updated the position every other key press, but that would need to be addressed if you allow direct entry into the field or arrow buttons are present on your keyboard.

Hi, thanks, but I checked that we are using Perspective not Vision.
I am trying to call it at Text Input. We built alphanumeric keyboard as a component so we dont use the tablet mode keyboard on touchscreen. So I dont know if its possible but it would be great work it like that, Text input is focused - touch of the button (lets say key A) and it checks caretp position and adds a key. I am afraid that when I touch the button, the focus is lost from Text input so the caret position would not work, am I wrong ? Or it is saving its position somewhere or I should use the approach you have given with saved caret position as custom property

Doesn’t appear to be supported, though I thought there was a forum post on the topic. Can’t find it at the moment.

There was something similar asked for a text area.
But yea its not possible without js.
You will lose focus of the input field.

I dont think you can succefully craft a keyboard like that. Except maybe with a very complex message system, which would be slow and traffic intensive for the gateway.

You should use an onscreen keyboard app seperate from igntion or something which matches the design you want.

1 Like