Detect when input box filled by keyboard and when by barcode scanner.

前端 未结 11 2070
星月不相逢
星月不相逢 2020-12-01 00:44

How I can programmatically detect when text input filled by typing on keyboard and when it filled automatically by bar-code scanner?

11条回答
  •  渐次进展
    2020-12-01 01:21

    Hi I have and alternative solution for evaluate a result of the bar code scanner without use of jQuery, first you need and input text that have a focus the moment that the barcode scanner is works

    
    

    The code in JavaScript is:

    var elmInputScan = document.getElementById('input_resultado');           
    
    elmInputScan.addEventListener('keypress', function (e){        
      clearInterval( timer_response );    
      timer_response = setTimeout( "onInputChange()", 10);
    });    
    

    When the barcode scanner input the text call serveral times to the keypress event, but only I interested to the final result, for this reason I use the timer. That's all, you can process the value into the onInputChange function.

    function onInputChange() {    
      console.log( document.getElementById('input_resultado').value );
    }
    

提交回复
热议问题