Using a scanner / Need event to happen on key press

Greetings. I am creating a screen that will be used at our facility that will log what’s been scanned, and who scanned it. Everything works fine with the exception I don’t know how to have this script fire after the enter key has been pressed. This is my script that I’ve put on the text box itself, I need this to happen automatically after the label has been scanned:

p = event.source.text
u = system.security.getUsername()

system.db.runPrepUpdate(“INSERT INTO endlinescan (Scan,userscanned) VALUES (?,?)”, [p, u])
system.gui.messageBox("Scan Complete " + p + " was scanned by: " + u)

I’m assuming the script needs to be attached to the actual text box itself, I don’t want a button for them to click, and I don’t want them being able to go back and edit what’s been scanned etc. I just need a simple logging to SQL table on each scan. Any help? Also, I’m under the assumption it’s on the “Key pressed” event in scripting, if that’s not accurate my apologies.

Easiest way is to utilize the propertyChange event on the text field component. If the scanner is appending an enter press, this should trigger the text property change to fire
Add:

if event.propertyName == “text”:

To the beginning of your script and place it into the propertyChange event and you should be good to go.

1 Like

You could do this in a transaction group, I have one that works just like this. drag the system/client/username tag plus the tag that is linked to the scanner. I have a text box that shows the barcode scanned, which has an event trigger to write value to a tag. Then set the transaction group to log this into your db on whatever event you want. I have mine trigger on value change to prevent from double scans being logged.

1 Like

You also might look at using a programmable scanner, the one I use has a set of barcodes you scan to program it to do certain things. Mine is programmed to automatically do a carriage return after the scan, you could try that too.

1 Like

This got me taken care of, Thank you sir!

awesome! and for code sake-
rather than using event.source.text with the prop change event you can use event.newValue

1 Like