VK_ENTER with virtual keyboard

Hi, I have a text field which waits for a keyReleased event of the VK_ENTER key, then it triggers a function to verify the value introduced, and if its correct it sends the text field value to the PLC.

This works fine with a physical keyboard, however as the virtual keyboard doesnt work with the key listener, I had to improvise the following solution to make it work, I used an auxiliar property named “clicked”, to prevent the validateInput function to be executed, when the text propertyChange is triggered at the component start.

mouseClicked event:

event.source.parent.clicked = 1

propertyChange event:

if event.propertyName=="text" and event.source.parent.clicked and shared.mylib.validateInput():
    event.source.parent.forcedValue= event.newValue
    event.source.parent.clicked = 0

I dont really like this solution, and I bet there is a better way to accomplish this. I hope somebody can give me a hint to solve this issue.


In situations like this where I want total control over sending edits back to the source, I add a custom property to the entry field that binds to the tag or whatever. Then I unidirectionally bind the field’s value or text property to that custom property. Then a propertyChange event on the field’s value or text property can check if the custom property already matches. If it does, then the change came from the system and can be ignored. If it doesn’t match, the change came from the user and you can script your update however you like. If the custom property has a bidirectional binding, you can simply set that property to trigger the writeback.

Thank you! That was really useful.