[Chicago-talk] distinguishing between tped input and scanned input.

Steven Lembark lembark at wrkhors.com
Fri Apr 15 00:30:10 PDT 2005



-- Richard Reina <richard at rushlogistics.com>

> I have a simple script that waits for a user to type
> in or scan in via the barcode scanner a five digit
> number.  Is there anyway to make the program
> distinguish between scanned input and typed input.  If
> the input is scanned I would like the program to not
> wait for return to be pressed.  I tried fooling around
> ReadKey but could not get the program to distingush
> between typed input and scanned input?
>
> Does anyone know how I can achieve this?

Instead of doing blocking reads use a polling read on
the raw device. The Camel documentation for "select"
describes this in some detail. The trick is to read
bytes from your input data stream until you get the
number of bytes, with a timeout that avoids accidentally
blocking on the port.

If you put the keyboard temporarily into raw mode you'll
get the individual bytes; when you get five of them just
flush the input stream and put it back in cooked mode
(readkey does most of this for you but sysread + select
gives finer control).

The point is to suck in bytes as they happen, which
requires being in raw mode.



-- 
Steven Lembark                                       85-09 90th Street
Workhorse Computing                                Woodhaven, NY 11421
lembark at wrkhors.com                                     1 888 359 3508


More information about the Chicago-talk mailing list