繁体   English   中英

从javascript捕获条形码阅读器(键盘 - 楔形)事件

[英]Capture barcode reader (keyboard-wedge) events from javascript

我正在开发一个必须在运行Android 4.4的Honeywell Dolphin 75e设备上使用的Web应用程序。 集成的条形码阅读器可以在“键盘楔形”模式下操作,但仅在文本字段具有焦点时才能操作。

使用桌面浏览器,我可以使用该代码捕获条形码阅读器事件:

var BarcodesScanner = {
    barcodeData: '',
    deviceId: '',
    symbology: '',
    timestamp: 0,
    dataLength: 0
};

function onScannerNavigate(barcodeData, deviceId, symbology, timestamp, dataLength){
    BarcodesScanner.barcodeData = barcodeData;
    BarcodesScanner.deviceId = deviceId;
    BarcodesScanner.symbology = symbology;
    BarcodesScanner.timestamp = timestamp;
    BarcodesScanner.dataLength = dataLength;
    $(BarcodesScanner).trigger('scan');
}

BarcodesScanner.tmpTimestamp = 0;
BarcodesScanner.tmpData = '';
$(document).on('keypress', function(e){
    e.stopPropagation();
    var keycode = (e.keyCode ? e.keyCode : e.which);
    if (BarcodesScanner.tmpTimestamp < Date.now() - 500){
        BarcodesScanner.tmpData = '';
        BarcodesScanner.tmpTimestamp = Date.now();
    }
    if (keycode == 13 && BarcodesScanner.tmpData.length > 0){
        onScannerNavigate(BarcodesScanner.tmpData, 'FAKE_SCANNER', '', BarcodesScanner.tmpTimestamp, BarcodesScanner.tmpData.length);
        BarcodesScanner.tmpTimestamp = 0;
        BarcodesScanner.tmpData = '';
    } else if (e.charCode && e.charCode > 0) {
        BarcodesScanner.tmpData += String.fromCharCode(e.charCode);
    }
});

$(BarcodesScanner).on('scan', function(e){
    alert();
});

不幸的是,它无法在Android上运行。 是否有API允许我捕获这些事件? 或另一个处理此问题的浏览器?

编辑:

我能够使用文本字段作为缓冲区拦截条形码阅读器的事件。

但在这种情况下,我不能使用任何需要在我的应用程序中焦点的控件。 这是一个很大的障碍。

 BarcodesScanner.tmpInput = $('<input />', { type: 'text', style: 'position: fixed; top: 0; right: 0; width: 0; height: 0;' }); $('body').append(BarcodesScanner.tmpInput); setInterval(function(){ BarcodesScanner.tmpInput.focus(); }, 500); BarcodesScanner.tmpInput.on('input', function(e){ if (BarcodesScanner.tmpInput.val().length > 0){ onScannerNavigate(BarcodesScanner.tmpInput.val(), 'FAKE_SCANNER', 'WEDGE', Date.now(), BarcodesScanner.tmpInput.val().length); BarcodesScanner.tmpInput.val('') } }); 

我终于收到了霍尼韦尔支持的功能响应:

我怀疑应用程序想要将数据作为Keydown / Keyup事件接收。

你能测试一下吗?

在Wedge上设置键:9,10,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76, 77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127

截图

由于手动操作可能需要15分钟,因此我创建了此代码,您可以在Wedge作为键字段内读取:

9,10,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54, 55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127

阅读完代码后,请在保存前等待10秒钟,然后退出并重新输入扫描仪设置,检查数据是否已正确保存到该字段中。

最后,禁用并重新启用扫描仪(或重启设备)。

然后扫描仪应该在您的应用程序上工作。

希望这可以帮助。

终端必须使用最新版本的系统才能看到“Wedge as keys”字段。 不要忘记将“\\ n”设置为后缀。

有了它,JS代码将是:

var BarcodesScanner = {
    barcodeData: '',
    deviceId: '',
    symbology: '',
    timestamp: 0,
    dataLength: 0
};

function onScannerNavigate(barcodeData, deviceId, symbology, timestamp, dataLength){
    BarcodesScanner.barcodeData = barcodeData;
    BarcodesScanner.deviceId = deviceId;
    BarcodesScanner.symbology = symbology;
    BarcodesScanner.timestamp = timestamp;
    BarcodesScanner.dataLength = dataLength;
    $(BarcodesScanner).trigger('scan');
}

BarcodesScanner.tmpTimestamp = 0;
BarcodesScanner.tmpData = '';
$(document).on('keypress', function(e){
    e.stopPropagation();
    var keycode = (e.keyCode ? e.keyCode : e.which);
    if (BarcodesScanner.tmpTimestamp < Date.now() - 500){
        BarcodesScanner.tmpData = '';
        BarcodesScanner.tmpTimestamp = Date.now();
    }
    if (keycode == 13 && BarcodesScanner.tmpData.length > 0){
        onScannerNavigate(BarcodesScanner.tmpData, 'FAKE_SCANNER', 'WEDGE', BarcodesScanner.tmpTimestamp, BarcodesScanner.tmpData.length);
        BarcodesScanner.tmpTimestamp = 0;
        BarcodesScanner.tmpData = '';
    } else if (e.charCode && e.charCode > 0) {
        BarcodesScanner.tmpData += String.fromCharCode(e.charCode);
    }
});

现在,您可以收听扫描事件:

$(BarcodesScanner).on('scan', function(e){
    alert(BarcodesScanner.barcodeData);
});

我希望这会帮助别人。

您是否尝试订阅不同的元素$('html,body')以及可能不同的事件keyup,keydown,textInput?

你使用的是JQuery mobile还是普通的?

更改密钥集并使用\\ n后缀适用于Android4.4。 它不适用于Android 6.0.1。 测试Dolphin CT50 ......

霍尼韦尔已经解决了这个问题你需要这个文件我想:HELSINKIAD_71.01.07.0050

请问霍尼韦尔,然后通过恢复模式更新它。

暂无
暂无

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

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