Barcode Scanner Detection

by masmiguel

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="//rawgit.com/kabachello/jQuery-Scanner-Detection/master/jquery.scannerdetection.js"></script>
 <input id="userInput" type="text"  autofocus/>


<br>

<div class="test">


   <input id="scannerInput" type="text" value="barcodescan" autofocus/>
</div>

JavaScript

$(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);

	
	}
	
	
});