I’d like to write a simple program that reads a barcode, and makes a note of the barcode as well as the time it was scanned in. Unfortunately I cannot guarantee that the program will have focus when the code is scanned. My understanding is that most barcode scanners act like a keyboard so if the program does not have focus I will have issues. What are the ways to deal with this? Note I’d prefer to code this in Java but I can use .net if the libraries make it easier. I also don’t have a specific scanner in mind so if one model will work better for this that info would be appreciated. I’ve sceen this question but it assumes the app has focus.
Although barcodes are designed to be "read" by scanners and interpreted by computers, it is possible with practice to look at a UPC barcode and translate it into a 12-digit number.
There are many reasons barcodes might not scan and most of them can be boiled down to one of three things—your equipment isn't suited to your barcodes, your scanner isn't being operated properly or your barcode labels aren't suited to your application or environment.
Barcode scanners do not require any special software or driver to function properly. They will emulate a keyboard and will be recognized by your computer as a general input device.
Laser barcode scanners are incapable of scanning barcodes displayed on screen simply because the screens/displays give off light themselves. This leads to light not being reflected back for the scanners to read.
Most barcode scanners behave like a keyboard, hence requiring the processing application to have input focus. There are however also barcode scanners, which connect to the serial port or are connected to the USB and offer a virtual serial port interface.
These scanners must be accessed through the real or virtual serial port. For Java, you will need to use the Java Communications API or any other 3rd party library offering access to the serial ports, since this is not possible with the standard Java API.
Most keyboard wedge barcode scanners can be configured (via configuration barcodes) to emulate a keypress of a function key before sending the barcode data. The Windows API includes a RegisterHotkey function to define system-wide hotkeys. When the hotkey is pressed, you could give focus to your program's window to read the barcode.
A Google search reveals a library to register system-wide hotkeys from Java. There's also a question on this site about it, which seems to suggest that there isn't a publicly available library to do so in Mac OS X, though one of the answerers posted a link to such a library he was developing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With