Domanda

I have a barcode scanner that needs to read data into a database whenever a barcode is scanned. All the scanner does is take the barcode and create a string with it. Barcodes, however can be variable lengths.

The idea behind it is to have a java class open, and the user will scan multiple barcodes one after the other (without pressing the enter key). This class must then take each barcode and read it into a database.

I need help to read the strings from the scanner without the user having to press enter each time (as this makes the program pretty useless and not very user friendly)

Thanks. Looking forward to finding a solution!

È stato utile?

Soluzione

I've done something similar to this in .NET but the concept should be about the same.

I would set a timer up with a delay long enough to be a sign that input has stopped but not too long to cause delay - so say 500ms.

On text box update event you ensure both that the timer is enabled and that you reset the timer essentially giving you another 500ms to enter more information.

On the timer tick event or equivalent you do your action (in your case save to the DB) and disable the timer, ensuring you don't affect focus during the processing obviously.

Assuming you also clear the text box, you can then after whatever delay you specify scan something else and trigger the exact same functionality.

Note this may fall down if you ever have to fall back to using a keyboard instead of barcode scanning. At the very least if this was the case you would need to research a better delay value that would accommodate both or maybe provide a way to disable the timer and revert back to using the enter key

Hope this helps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top