【发布时间】:2019-03-13 15:30:48
【问题描述】:
所以,我有一个条形码扫描仪,通过 microsub (otg) 连接,它被识别为外部键盘。我需要做的是随时捕捉任何 keydown 或 keypress 事件(不仅仅是专注于输入)。此外,很高兴知道事件是由虚拟键盘还是物理键盘触发的。
有什么想法吗?
【问题讨论】:
标签: javascript angularjs ionic-framework ionic3
所以,我有一个条形码扫描仪,通过 microsub (otg) 连接,它被识别为外部键盘。我需要做的是随时捕捉任何 keydown 或 keypress 事件(不仅仅是专注于输入)。此外,很高兴知道事件是由虚拟键盘还是物理键盘触发的。
有什么想法吗?
【问题讨论】:
标签: javascript angularjs ionic-framework ionic3
你好 jonyjm Bellow 是带有 cdn 链接的扫描仪示例
1 Scann with focus 扫描器输入文本框或在此处输入 例如,这将显示在顶部文本框中
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<input id="userInput" type="text" autofocus />
<br>
<div class="test">
<input id="scannerInput" type="text" value="barcodescan" autofocus />
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/scannerdetection/1.2.0/jquery.scannerdetection.compatibility.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/scannerdetection/1.2.0/jquery.scannerdetection.min.js"></script>
<script>
$(document).ready(function () {
$(document).scannerDetection({
//https://github.com/kabachello/jQuery-Scanner-Detection
timeBeforeScanTest: 200, // wait for the next character for upto 200ms
avgTimeByChar: 40, // it's not a barcode if a character takes longer than 100ms
preventDefault: true,
endChar: [13],
onComplete: function (barcode, qty) {
validScan = true;
$('#scannerInput').val(barcode);
} // main callback function ,
,
onError: function (string, qty) {
$('#userInput').val($('#userInput').val() + string);
}
});
});
</script>
</body>
</html>
【讨论】: