Gain focus on a numeric text field when barcode enters a value

Hello everyone,

For a project, I have a barcode and multiple numeric entry text fields on my screen. Currently, the barcode is entering the value into whatever numeric entry box I am in by clicking the mouse on it. However, I want to be able to choose the tag the barcode should enter a value in. The operator might not even have access to a screen or a mouse.
I know that there is a way to do this in Ignition? (Both in vision and perspective) but not sure about it.
https://docs.inductiveautomation.com/display/DOC81/Focus+Manipulation

I am using a USB barcode scanner.

Thank you!

In vision you can use:

event.source.requestFocusInWindow()

In perspective

self.focus()
1 Like

Thank you very much for your response!
Where should I use this script?
Script editor of the numeric text field? and in what event? focus?

In Vision you can add a custom property (name: scan) to the text field and bind it to the tag, then add a script on property change:

if event.propertyName == "scan":
     event.source.requestFocusInWindow()

In Perspective is similar, right click on custom property, also binding it to the tag, and click on Add Change Script
then add the script:

self.focus()
1 Like

Thank you!
When the barcode wants to enter the value, non of my text field gets the value, unless I click on one of them and then the barcode value is entered into that field.

So this is what I did:
I created a numeric text field and bound its “Long” value to a memory tag called “barcode scan”. I also created a property for that text field as you mentioned and put its data type to Long:

image

I bound that property to the “barcode scan” tag I mentioned above. I wrote the script for the property change of that numeric text field using the script editor.

if event.propertyName == "scan":
     event.source.requestFocusInWindow()

Oh! If you are have a binding already to the tag on value property, you can delete the custom property and use “value” property instead of “scan”.

You mean I should write this instead?

if event.propertyName == "LongValue":
     event.source.requestFocusInWindow()

cause it is not working either.

if event.propertyName == "longValue":
     event.source.requestFocusInWindow()

with lower case, but yes

1 Like

Unfortunately, it is not working. I do not see the cursor on that numeric text field when I launch the project, and all of the text fields are the same and I cannot enter the barcode value unless I click on one of them.

It works! I just tested it.
Let me try to understand what you want. When ever the value of the barcode changes, you want to cursor be on numeric text field ready to type?
If that is what you need I already did it and it works.

1 Like

Yes and No.

So if I want the cursor to be on a numeric text field whenever the value of the barcode changes, I should use the same approach you told me, so basically:

  1. create a numeric text field
  2. bound its long value to a memory tag called “barcode scan”
  3. do scripting for that numeric text field component as below:

And it should work! But it is not working :frowning: When I launch the project that numeric text field does not have the cursor.

The other thing that I want is that whenever the window opens I want a specific numeric field to listen to the barcode. So for this application, we have the barcode far from the screen, and the computer and operator cannot click on the text field, basically, the screen should constantly wait for the barcode to be entered. When the barcode is entered it should automatically go to that numeric field. I was hoping to use this:


(system.gui.getParentWindow(event).getComponentForPath('Root Container.BarcodeScanner').longValue).requestFocusInWindow()
based on this link:
https://docs.inductiveautomation.com/display/DOC81/Focus+Manipulation

But it is not working as my script is wrong

When I have trouble with property change events, sometimes its helpful to put this script at the very top in the propertyChange script window to verify that the property you expect is actually firing.

print event.propertyName
1 Like

Thank you!

So I do see the barcode is being printed on top of that statement but I do not see the cursor on the numeric field itself.

043100069096
667888327577
667888327577
print event.propertyName
if event.propertyName == "longValue":
     event.source.requestFocusInWindow()

this is syntax mistake, you only call the focus as a method. delete parenthesis at beginning a after longValue and delete longValue

1 Like

This should not be that complicate.
Anyway, toggle to True the Defer Updates property, and to create a virtual mouseRelease event you can do it with:

if event.propertyName == "longValue":
	event.source.requestFocusInWindow()
	def click():
		from java.awt.event import MouseEvent
		from java.lang import System
		target = event.source
		id = MouseEvent.MOUSE_RELEASED
		when = System.currentTimeMillis()
		x = target.getX()
		y = target.getY()
		click = MouseEvent(target, id, when, 0, x, y, 1, False)
		event.source.dispatchEvent(click)
	system.util.invokeLater(click)
1 Like

You can also try this:
https://www.sepasoft.com/products/barcode-scanner/

1 Like

Just as a reference for others:

I used InternalFrameActivated event handlers on the scripting feature of my main window and I wrote the script below in that option:

system.gui.getParentWindow(event).getComponentForPath('Root Container.BarcodeScanner').requestFocusInWindow()

And it worked! Now whenever the window opens up, the numeric entry box has focus and the user can directly enter number into it.

1 Like

That’s what I use :slight_smile:

1 Like