views:

742

answers:

3

Hi:

I have a Symbol LS2208 barcode scanner and works OK in my linux box (Kubuntu 8.10 Intrepid Ibex). Whenever you scan a barcode the scanner (connected to an USB port) sends the reading to wherever the text caret is. I would like to redirect all the readings from the scanner to an specific widget in my application (i.e. a text edit control). How can I do it? Though I use C++ with Qt GUI library sample code is welcome in any language or GUI library.

+2  A: 

I don't know the answer, but here are some suggestions to find out what your options are:

  1. Install an event filter on QCoreApplication::instance() (or reimplement QCoreApplication::notify())
  2. In event filter handler, output each event looking for anything useful:

    void eventFilter(QObject *obj, QEvent *evt) {
        qDebug() << obj << evt;
    }
    
  3. Examine the debug output to determine which events are triggered by the scanner.

qDebug() understands virtually every type and should give you reasonable output that will allow you to tell whether the it's coming in as keyboard events or something else.

Kaleb Pederson
+3  A: 

That may be tricky in that most barcode scanners are also known as keyboard wedges. They function as a keyboard and shove keys into the event stream so as to be as indistinguishable from a keyboard as possible. This makes for the greatest compatibility.

Many USB barcode scanners publish themselves as a HID endpoint and then for all intents and purposes, they ARE keyboards.

There are a number of things you can try to do - many scanners are configurable to allow them to spew in a prefix and suffix around the barcode data. If you can test for that, you just send the string to the right place. This is unpalatable in that you have to metaprogram the scanner. Usually this is done with a special set of barcodes. Here is a link to the manual for your scanner. On page 249, there are barcodes for metaprogramming the prefix and suffix.

You might want to figure out how to be a client for the HID events and redirect the scanner events where you want them. I've never tried to do this on LINUX. It's a pain on both Windows and OS 9 era Mac (the last time I played with USB extensively).

plinth
+1  A: 

It seems like there is a problem with the accepted answer. The input is going to be processed by whatever is considered to be the active application. Thus, if someone brings up a web browser and then starts scanning barcodes, the input goes to the web browser and not the application. The desired application won't even see the events.

If the application is active, then you can trap the events and eventually figure out which ones are coming from the barcode scanner. Then the appropriate widget can be activated to receive the input.

Michael Mathews