簡體   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