Barcode Scanner and Keyboard Problem

Barcode scanner and keyboard. NOTE. My barcode scanner is a USB type. enter image description here

Then... enter image description here

What function should I use to launch the keyboard if I'm on the auto.aspx page? I tried this code but did not succeed:

var barcode = document.getElementById('barcodenum'); barcode.addEventListener("keypress", function() { alert("Please use Barcode Scanner!"); document.getElementById('barcodenum').value = "";}, true); 
+2
source share
3 answers

As @Robert Skarzycki noted above, I doubt that you can integrate with the scanner using a web page.

In the issue of intercepting keystrokes.

Add this to the chapter section of your page.

  <script type="text/javascript"> window.onload = function() { var barcode = document.getElementById('barcodenum'); barcode.addEventListener("keyup", function() { alert("Please use Barcode Scanner!"); document.getElementById('barcodenum').value = ""; }, true); }; </script> 
+2
source

I'm afraid you cannot do this via JavaScript. If you were developing a desktop application, you can do it.

EDIT: The only solution in JavaScript is the time between keypress events. A barcode scanner is faster than a human one, so if you set up an experimentally invented timeline for the intervals between two keystrokes, you can deal with this problem. ( Source of this idea.)

+3
source

Try this code. I assume you know about jQuery. Run this code and enter something from the keyboard while focusing the web page and press the enter key. If this works, the barcode reader does the same. Set up a barcode reader to enter the input key at the end of the code reading. JQuery library

 <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script> 

Jquery

 $(document).ready(function() { var barcode=""; $(document).keydown(function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code==13)// Enter key hit { alert(barcode); } else if(code==9)// Tab key hit { alert(barcode); } else { barcode=barcode+String.fromCharCode(code); } }); }); 
0
source

All Articles