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