Javascript:如何最好地阅读手持式条形码扫描仪? [英] Javascript: How to read a hand held barcode scanner best?

查看:172
本文介绍了Javascript:如何最好地阅读手持式条形码扫描仪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过手持式扫描仪扫描条形码并使用Javascript处理结果。

I'd like to be able to scan barcodes via a hand held scanner and handle the results with Javascript.

条形码扫描仪几乎像键盘一样工作。它输出扫描/翻译(条形码 - >数字)数据原始(对吗?)。实际上我只需要捕获输出并继续。但是怎么样?

A barcode-scanner works almost like a keyboard. It outputs the scanned/translated (barcode->number) data raw (right?). Actually I just need to catch the output and proceed. But how?

这里有一些我想做的伪代码:

Here's some pseudocode I'd like to make work:

$(document).on("scanButtonDown", "document", function(e) {
    // get scanned content
    var scannedProductId = this.getScannedContent();

    // get product 
    var product = getProductById(scannedProductId);

    // add productname to list
    $("#product_list").append("<li>" + product.name + "</li>");
});




  • 任何想法(框架,插件,片段)?

  • 任何条形码扫描仪(硬件)推荐?

  • 提前致谢!

    我发现这个这个好问题,但我想获得有关处理的更多信息。在我的情况下,仅仅关注textarea可能是不够的。

    I found this and this good questions but I'd like to get more information about the handling. Just to focus a textarea may be not enough in my case.

    推荐答案

    你的伪代码不起作用,因为您无权访问扫描程序以捕获 scanButtonDown 等事件。您唯一的选择是HID扫描仪,其行为与键盘完全相同。要区分扫描仪输入和键盘输入,您有两种选择:基于计时器或基于前缀。

    Your pseudo code won't work, because you don't have access to the scanner to catch events like scanButtonDown. Your only option is a HID scanner, which behaves exactly like a keyboard. To differentiate scanner input from keyboard input you have two options: Timer-based or prefix-based.

    基于计时器

    扫描仪可能比使用键盘(明智地)更快地输入字符。计算接收击键的速度并缓冲快速输入到变量中以传递给 getProductsId 函数。 @Vitall写了一个可重复使用的jQuery解决方案来捕获条形码扫描器输入,你只需要捕获onbarcodescanned事件。

    The scanner is likely to input characters much quicker than a user can (sensibly) with a keyboard. Calculate how quickly keystrokes are being received and buffer fast input into a variable to pass to your getProductsId function. @Vitall wrote a reusable jQuery solution for catching barcode scanner input, you would just need to catch the onbarcodescanned event.

    基于前缀的

    大多数扫描仪都可以配置为所有扫描数据的前缀。您可以使用前缀开始拦截所有输入,一旦您获得了条形码,就可以停止拦截输入。

    Most scanners can be configured to prefix all scanned data. You can use the prefix to start intercepting all input and once you've got your barcode you stop intercepting input.

    完全披露:我工作作为制作手持式扫描仪的Socket Mobile公司的顾问。

    Full disclosure: I work as a consultant to Socket Mobile, Inc. who make handheld scanners.

    这篇关于Javascript:如何最好地阅读手持式条形码扫描仪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆