Login  Register

Re: Reading from barcode scanner

Posted by dscho on Feb 10, 2008; 12:55pm
URL: http://imagej.273.s1.nabble.com/Reading-from-barcode-scanner-tp3697230p3697235.html

Hi,

On Sun, 10 Feb 2008, Emilio Miguelanez Martin wrote:

> Johannes,
>
> > System.in is usually the channel that takes the keyboard input in the
> > terminal.  I fail to see how using System.in to read from a barcode
> > scanner via USB could be correct, ever.
>
> Well, I can tell that it works perfectly.

But you cannot tell why, evidently. ;-)

The scanner driver translates the events into _keyboard_ events.  So it
makes _no difference_ for _any_ program if you _type in_ the numbers, or
_scan in_ the barcode.  The input will be _keyboard events_.

So if you have a console program, you can read stdin.  If you have a GUI
program, you have to handle the keyboard events _differently_.  The method
addKeyListener() comes to mind.

Hth,
Dscho