简体   繁体   English

将条形码扫描到Web应用程序的文本框中

[英]Scanning barcode into the textbox of a web application

I am working on a web based Java application (GWT is used for my UI). 我正在使用基于Web的Java应用程序(UI使用GWT)。 I have a warehouse management system.I need to scan the barcodes and show them in a textbox. 我有一个仓库管理系统,我需要扫描条形码并将其显示在文本框中。 I am aware that the scanners would send keyboard events. 我知道扫描仪会发送键盘事件。 How do I capture these events and populate them in my textbox ? 如何捕获这些事件并将其填充到我的文本框中? Should the cursor focus be on the textbox while scanning the barcode ? 扫描条形码时,光标应该位于文本框上吗?

Can anyone please provide a code snippet of how to capture these events and populate in the textbox ? 任何人都可以提供如何捕获这些事件并在文本框中填充代码片段吗?

Please note that this needs to work across different OS and browsers. 请注意,这需要在不同的操作系统和浏览器上工作。 This should work for laptops/desktops. 这应该适用于笔记本电脑/台式机。 It is not for mobile apps. 它不适用于移动应用程序。

I would recommend setting cursor focus on the input textbox if scanning barcodes is the default action for that page, you can then use a KeyPressHandler on the textbox to intercept the scanner's control character if its set up to fire off a carriage return line feed (enter key) after each scan. 如果该页面的默认操作是扫描条形码,我建议将光标放在输入文本框上,然后,如果该文本框设置为触发回车换行符,则可以在文本框上使用KeyPressHandler来拦截扫描仪的控制字符(输入键)。

This may be a place to start looking. 可能是一个开始寻找的地方。

A quick search for an example came up with a good one here 快速搜索一个例子, 在这里找到了一个很好的例子

Since you cannot distinguish between scanner and keyboard events, just focus on the textbox and wait for the input. 由于无法区分扫描仪事件和键盘事件,因此只需将焦点放在文本框上并等待输入。 Be sure to set up the scanners so they send TAB afterwards, not ENTER. 确保设置扫描仪,以便它们随后发送TAB,而不是ENTER。

Depending on you scanner, it is possible to program it to send a predefined prefix before the actual bar code. 根据扫描仪的不同,可以对其进行编程以在实际条形码之前发送预定义的前缀。 For example, the scanner I was working with, a Honeywell Voyager 95X0 , can be configured to transmit, for example, a Start of TeXt (ASCII 02H) before each bar code (see page Chapter 8, page 42 of the configuration guide). 例如,我使用的扫描仪Honeywell Voyager 95X0可以配置为在每个条形码之前发送例如Start of TeXt (ASCII 02H)Start of TeXt (ASCII 02H) (请参阅配置指南第8章,第42页 )。 You could then use that prefix to filter out which KeyPressEvents were coming from the scanner (and then move the input to the text box) and which were from the user. 然后,您可以使用该前缀来过滤出哪些KeyPressEvent来自扫描仪(然后将输入移至文本框)以及哪些来自用户。

Setting up a "global" KeyPressHandler (so that the user doesn't have to remember to focus the text box before scanning the bar code) should be trivial - see, for example, this thread . 设置“全局” KeyPressHandler(这样,用户在扫描条形码之前不必记住要聚焦文本框)应该很简单-例如,参见此线程 The key point is using Event.addNativePreviewHandler to capture the events before they are fired to their handlers. 关键是使用Event.addNativePreviewHandler捕获事件,然后再将事件触发到其处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM