2

Bar Code Scanner and Keyboard. NOTE: My Bar Code Scanner is USB Type. enter image description here

Then... enter image description here

What function must be use to trigger the keyboard if i'm at auto.aspx page? I tried this code but no success:

var barcode = document.getElementById('barcodenum'); barcode.addEventListener("keypress", function() { alert("Please use Barcode Scanner!"); document.getElementById('barcodenum').value = "";}, true); 
5
  • 1
    Why can't you use the same screen for both methods of barcode input? Seems like you're creating more work for yourself... Commented Jan 30, 2013 at 14:17
  • @markpsmith that's why we bought scanner. The manual is only for alternative use. Besides it's our thesis professor request. not ours. Commented Jan 30, 2013 at 14:24
  • @PetersonPilares is the scanning not activating your keyup event? Commented Jan 30, 2013 at 14:52
  • @PetersonPilares In your accepted answer. I use a similar event, and the scanner activates it. So I'm curious if this is working for you where it only alerts when they type, but not when they scan. Commented Jan 30, 2013 at 15:01
  • @MikeSmithDev Yes Mike, it alerts me when I inputting data using keyboard, I must use the scanner to prevent the alert message. Commented Jan 30, 2013 at 15:05

3 Answers 3

3

I'm afraid you can't do that through JavaScript. If you were developing desktop app, it could be done.

EDIT: The only one solution in JavaScript is measure the time between the keypress events. Barcode scanner is faster then human, so if you set the - experimentally invented - time limet for gaps between two keypresses, you may cope with this problem. (Source of this idea.)

Sign up to request clarification or add additional context in comments.

Comments

2

As pointed out by @Robert Skarzycki above, i doubt you can integrate with the scanner using a web page.

On the keypress intercept issue.

Add this to the head section of you 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> 

1 Comment

No, integrating a scanner is easy. It's just that he won't be able to differentiate between a keyboard press and a scanner scan.
0

Try this code. I assum that you know about the Jquery. Run this code and type anything from the keyboard while focusing the web page and hit enter key. If this works barcode reader do the same. Configure your barcode reader to pass enter key at the end of 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); } }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.