Login  Register

Re: Reading from barcode scanner

Posted by Michael Schmid on Feb 11, 2008; 10:34am
URL: http://imagej.273.s1.nabble.com/Reading-from-barcode-scanner-tp3697230p3697236.html

Hi Dscho, Emilio,

hmm, I do not agree that you should get keyboard events from
the barcode scanner.
See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#in

public static final InputStream System.in
quote
The "standard" input stream. This stream is already open and
ready to supply input data. Typically this stream corresponds
to keyboard input or another input source specified by the
host environment or user.
end_quote

As far as I know, ImageJ itself does not change System.in, so
I suspect that the ImageJ launcher (ImageJ.app on Mac,
ImageJ.exe on the PC) somehow modifies it.
On Windows, you might try to change "javaw" into "java" in the
ImageJ.cfg file, maybe this helps. It will create a console
(DOS-like) window in addition to ImageJ.

Michael
________________________________________________________________

> 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