【问题标题】:Ionic 3: How to get keydown/keypress events on external keyboard at any timeIonic 3:如何随时在外部键盘上获取 keydown/keypress 事件
【发布时间】:2019-03-13 15:30:48
【问题描述】:

所以,我有一个条形码扫描仪,通过 microsub (otg) 连接,它被识别为外部键盘。我需要做的是随时捕捉任何 keydown 或 keypress 事件(不仅仅是专注于输入)。此外,很高兴知道事件是由虚拟键盘还是物理键盘触发的。

有什么想法吗?

【问题讨论】:

    标签: javascript angularjs ionic-framework ionic3


    【解决方案1】:

    你好 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>

    【讨论】:

    • 感谢您的回答。我没有使用 jquery,因为它是一个 ionic/angular 项目。
    • 只需使用 jquery 进行数据捕获,然后按角度获取
    • 使用 jquery 超出了本项目的范围,我正在寻找离子原生解决方案
    • 嗨,如果您需要,您是正确的,然后可以通过 var scannerdata = angular.element(document.querySelector('#userInput')); 访问范围内的内容;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多