2

我正在开发一个必须在运行Android 4.4的Honeywell Dolphin 75e设备上使用的Web应用程序。 集成的条形码阅读器可以在“键盘楔形”模式下操作,但只能在文本字段有焦点时使用。从javascript中捕获条形码读取器(键盘 - 楔形)事件

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

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('') 
    } 
}); 

回答

4

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

我怀疑应用程序想要接收数据的keydown/ KEYUP事件。

你可以请测试以下吗?

按键设置的楔形: 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

Screenshot

,因为它可能需要15分钟做手工,我创造了这个 代码,您可以在里面楔形读作键字段:

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秒,检查 如果数据是通过退出并重新进入 扫描仪设置正确保存到该字段。

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

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

希望这会有所帮助。

终端必须使用系统的最新版本才能看到“楔形为键”字段。 不要忘记将“\ 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); 
}); 

我希望这会帮助别人。

+0

谢谢你的分享,这是很棒的东西,我正在寻找同样的东西。 Hower,在我的应用程序中,每次扫描时都会显示键盘。这也发生在你身上吗?有关如何摆脱它的任何建议? – user1051218

+0

通常,键盘仅在输入字段中显示,那么您是使用本答案中公开的捕获解决方案还是原始问题编辑中的文本字段缓冲区?您可以使用空键盘(https://play.google.com/store/apps/details?id=com.wparam.nullkeyboard&hl=fr)等应用停用它。 什么是您的设备? –

+1

对于没有“楔子作为钥匙”选项的Dolphin 75e用户,您需要联系霍尼韦尔支持以获取最新的固件,因为由于授权问题,它们不在其网站上提供。相关文件是'PARISAD_56.01.13.0173.zip'。 – SystemParadox

1

你试过订阅不同的元素$( 'HTML,身体'),也许不同的事件KEYUP,KEYDOWN,为textInput?

你是使用JQuery移动还是正常?

+0

我正在使用JQuery正常。 我可以将条形码事件捕获为文本字段上的“输入”事件,但不是在主体上。 –

+0

我的办公桌上有2台扫描仪(2d /条形码和信用卡),正在为售货亭开发几页。你的代码适用于我的win7 + chrome。我试过document.addEventListener(“tap”,function(e){alert(e)});在我的SG s5上 - 工作正常。虽然我订阅了文档,但也捕获了android键盘事件(document.addEventListener(“keydown”,...))。我会尝试连接蓝牙键盘,以检查是否可以捕获该键盘,这意味着扫描仪不会像键盘一样工作。 – faster

+0

只有当输入字段具有焦点时,扫描仪才能用作键盘。 –

0

更改键集并使用\ n后缀适用于Android4.4。它不适用于Android 6.0.1。 测试对海豚CT50 ...

+0

我会在10天内收到2个带有Android 6.0的Dolphin 75e,所以我会告诉你它是否有效。 –

+0

我们的设备与Android 6.0具有buildnumber:71.01.04.0015。 http://hsm.force.com/publickb/articles/HSM_Article/CT50-Android-6-0-does-not-jump-to-next-field-in-web-browser-after-scanning-a-条形码/?q = ct50 + wedge&l = en_US&fs =搜索&pn = 1 霍尼韦尔网站上找不到版本71.01.07.0050 – HoneywellCT50

-1

霍尼韦尔在该问题上的修复,你需要这个文件,我认为:HELSINKIAD_71.01.07.0050

问霍尼韦尔,以后你通过恢复模式来更新它..

+1

您可以编写原始答案,而不是编写多个答案。 – Aloso