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.
我有一个Symbol LS2208条形码扫描仪,可以在我的linux盒子里工作正常(Kubuntu 8.10 Intrepid Ibex)。无论何时扫描条形码,扫描仪(连接到USB端口)都会将读数发送到文本插入符所在的位置。我想将扫描仪的所有读数重定向到我的应用程序中的特定小部件(即文本编辑控件)。我该怎么做?虽然我使用C ++和Qt GUI库,但欢迎任何语言或GUI库中的示例代码。
3 个解决方案
#1
I don't know the answer, but here are some suggestions to find out what your options are:
我不知道答案,但这里有一些建议可以找出你的选择:
- Install an event filter on QCoreApplication::instance() (or reimplement QCoreApplication::notify())
-
In event filter handler, output each event looking for anything useful:
在事件过滤器处理程序中,输出每个事件以查找有用的内容
void eventFilter(QObject *obj, QEvent *evt) { qDebug() << obj << evt; }
- Examine the debug output to determine which events are triggered by the scanner.
在QCoreApplication :: instance()上安装事件过滤器(或重新实现QCoreApplication :: notify())
检查调试输出以确定扫描程序触发了哪些事件。
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.
qDebug()几乎可以理解每种类型,并且应该为您提供合理的输出,以便您可以判断它是否作为键盘事件或其他内容进入。
#2
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.
许多USB条形码扫描仪将自己发布为HID端点,然后出于所有意图和目的,它们都是键盘。
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.
您可以尝试执行许多操作 - 许多扫描仪都可以配置为允许它们在条形码数据周围添加前缀和后缀。如果你可以测试它,你只需将字符串发送到正确的位置。这是不可接受的,因为你必须对扫描仪进行元编程。通常这是通过一组特殊的条形码完成的。以下是扫描仪手册的链接。在页249,有用于元编程前缀和后缀的条形码。
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).
您可能想知道如何成为HID事件的客户端,并将扫描仪事件重定向到您想要的位置。我从未试图在LINUX上这样做。这对Windows和OS 9时代的Mac都是一种痛苦(上一次我广泛使用USB)。
#3
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.
似乎接受的答案存在问题。输入将由被认为是活动应用程序的任何内容处理。因此,如果有人打开Web浏览器然后开始扫描条形码,则输入将转到Web浏览器而不是应用程序。期望的应用程序甚至不会看到事件。
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.
如果应用程序处于活动状态,那么您可以捕获事件并最终确定哪些事件来自条形码扫描器。然后可以激活相应的小部件以接收输入。
#1
I don't know the answer, but here are some suggestions to find out what your options are:
我不知道答案,但这里有一些建议可以找出你的选择:
- Install an event filter on QCoreApplication::instance() (or reimplement QCoreApplication::notify())
-
In event filter handler, output each event looking for anything useful:
在事件过滤器处理程序中,输出每个事件以查找有用的内容
void eventFilter(QObject *obj, QEvent *evt) { qDebug() << obj << evt; }
- Examine the debug output to determine which events are triggered by the scanner.
在QCoreApplication :: instance()上安装事件过滤器(或重新实现QCoreApplication :: notify())
检查调试输出以确定扫描程序触发了哪些事件。
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.
qDebug()几乎可以理解每种类型,并且应该为您提供合理的输出,以便您可以判断它是否作为键盘事件或其他内容进入。
#2
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.
许多USB条形码扫描仪将自己发布为HID端点,然后出于所有意图和目的,它们都是键盘。
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.
您可以尝试执行许多操作 - 许多扫描仪都可以配置为允许它们在条形码数据周围添加前缀和后缀。如果你可以测试它,你只需将字符串发送到正确的位置。这是不可接受的,因为你必须对扫描仪进行元编程。通常这是通过一组特殊的条形码完成的。以下是扫描仪手册的链接。在页249,有用于元编程前缀和后缀的条形码。
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).
您可能想知道如何成为HID事件的客户端,并将扫描仪事件重定向到您想要的位置。我从未试图在LINUX上这样做。这对Windows和OS 9时代的Mac都是一种痛苦(上一次我广泛使用USB)。
#3
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.
似乎接受的答案存在问题。输入将由被认为是活动应用程序的任何内容处理。因此,如果有人打开Web浏览器然后开始扫描条形码,则输入将转到Web浏览器而不是应用程序。期望的应用程序甚至不会看到事件。
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.
如果应用程序处于活动状态,那么您可以捕获事件并最终确定哪些事件来自条形码扫描器。然后可以激活相应的小部件以接收输入。