简体   繁体   English

用栏杆输入条形码,而无需单击输入字段

[英]rails input barcode without clicking into input filed

I'm curious right now if it's possible to have a usb barcode scanner connected to a pc and if you just scan something it should just check the database for the product. 我现在很好奇,是否有可能将USB条形码扫描仪连接到PC上,如果您只是扫描某些东西,则应该只检查产品数据库。

more details: 更多细节:

We got a CRM written in rails now if you click on a input field you can simple scan and everything is just fine but is it possible to let the people do whatever they want but if they scan it should automatically check the database for the product? 现在,我们获得了用Rails编写的CRM,如果您单击输入字段就可以进行简单扫描,一切都很好,但是是否可以让人们做他们想做的事,但是如果他们扫描了,应该自动检查产品的数据库? even if they don't click into a input field? 即使他们没有单击输入字段?

scanner: http://www.conrad.at/medias/global/ce/9000_9999/9100/9140/9144/914408_LB_00_FB.EPS_1000.jpg 扫描仪: http : //www.conrad.at/medias/global/ce/9000_9999/9100/9140/9144/914408_LB_00_FB.EPS_1000.jpg

tl;dr tl; dr

usb barcode scanner -> scanning and query database without clicking into input fields USB条码扫描器->无需单击输入字段即可扫描和查询数据库

edit: 编辑:

Alright now i have copied some code from a site, it bassically captures the barcode and prints it out. 好了,现在我已经从某个站点复制了一些代码,它以粗暴的方式捕获条形码并将其打印出来。 Now I'd like to hide the form but still get the input printed is this possible somehow? 现在,我想隐藏表单,但仍然可以打印输入内容,这是否可能?

http://www.deadosaurus.com/demos/barcode.html http://www.deadosaurus.com/demos/barcode.html

There is a form but i just want a keylogger like tool which checks for any input without input fields. 有一种形式,但是我只想要一个键盘记录器之类的工具,它可以检查没有输入字段的任何输入。

Thanks guys! 多谢你们!

    var pressed = false; 
    var chars = []; 
    $(window).keypress(function(e) {
        if (e.which >= 48 && e.which <= 57) {
            chars.push(String.fromCharCode(e.which));
        }
        console.log(e.which + ":" + chars.join("|"));
        if (pressed == false) {
            setTimeout(function(){
                if (chars.length >= 10) {
                    var barcode = chars.join("");
                    console.log("Barcode Scanned: " + barcode);
                    // assign value to some input (or do whatever you want)
                    $("#barcode").val(barcode);
                }
                chars = [];
                pressed = false;
            },500);
        }
        pressed = true;
    });
});
$("#barcode").keypress(function(e){
    if ( e.which === 13 ) {
        console.log("Prevent form submit.");
        e.preventDefault();
    }
});

This is possible, I've done it once for a warehouse application. 这是可能的,我已经为仓库应用程序完成过一次。 But it might depend on the type of barcode scanner you use. 但这可能取决于您使用的条形码扫描仪的类型。

Most barcode scanners will return the scanned code terminated by a newline character . 大多数条形码扫描仪将返回以换行符终止的扫描代码。 If you focus the input field after the page has loaded, the user can scan a product and the form will be submitted automatically. 如果在页面加载后将输入字段聚焦,则用户可以扫描产品,并且表单将自动提交。

So it's as simple as: 如此简单:

<form action="..." method="post">
  <input type="text" name="barcode" autofocus />
</form>

This theoretically, is possible. 从理论上讲,这是可能的。

Most barcode scanners can be programmed, by scanning programming barcodes from the manual. 通过扫描手册中的编程条形码,可以对大多数条形码扫描仪进行编程。

In our application, every barcode scanner gets programmed to have a prefix followed by the scanned data, and then suffix, which as @zwippie pointed out is usually carriage return (enter key) character. 在我们的应用程序中,每个条形码扫描仪都被编程为具有一个前缀,后跟扫描数据,然后是后缀,如@zwippie所指出的,通常是回车(输入键)字符。

[prefix] + [data] + [suffix] [前缀] + [数据] + [后缀]

So you could watch for the prefix, capture the data, and submit on the carriage return. 因此,您可以注意前缀,捕获数据并在回车符上提交

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

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