Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read barcode when program doesn't have focus?

Tags:

java

.net

barcode

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.

like image 627
Jared Avatar asked Nov 22 '10 19:11

Jared


People also ask

Can you manually read a barcode?

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.

Why won't my scanner read a barcode?

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.

Do you need a program for a barcode scanner?

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.

Can you scan a barcode on a computer screen?

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.


2 Answers

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.

like image 99
jarnbjo Avatar answered Nov 15 '22 10:11

jarnbjo


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.

like image 27
PleaseStand Avatar answered Nov 15 '22 09:11

PleaseStand