3

How can I emulate keyboard press once I scanned a barcode using a usb barcode scanner? I don't have any idea about this and I just want to get some suggestions/instructions on how can I do it. If I have this form, how will the barcode number be inputted in that textbox? thanks!

<form method="post" action="">
    <input type="text" id="barcode-input" name="barcode-input" value=""/>
</form>
fart-y-goer
  • 747
  • 3
  • 8
  • 27
  • I don't understand the question. You want to know how to set the value with jQuery? What to do with the barcode scanner? – MonkeyMonkey May 19 '12 at 13:02
  • I don't understand what you're trying to do. Does your barcode scanner wedge the keyboard? If you open notepad and scan something, do you see the output in notepad? – tzerb May 19 '12 at 13:02
  • No, how can I input the barcode value in the textbox using the barcode scanner. I don't have the manual/software/instructions for the barcode. – fart-y-goer May 19 '12 at 13:04
  • I know that the barcode scanner is detected as a hid. What I don't know is how the web app detect the barcode and put it into the textbox. Thanks – fart-y-goer May 19 '12 at 13:06

2 Answers2

7

The barcode scanners that I have seen (not that many I have to admit) act like a keyboard. Old ones even have a PS/2 port. But even the USB ones like to just identify themselves as a keyboard. When you scan a code, the scanner behaves as if you would have actually pressed number keys on your keyboard, probably ending with a return key.

So what you do is put a focus in your textbox, and scan your code and be done.

Roko
  • 1,233
  • 1
  • 11
  • 22
yankee
  • 38,872
  • 15
  • 103
  • 162
0

If your scanner doesn't work like a keyboard, and you have to get the code programmatically, you'll have to use an automation tool.

Depending on what language you're working with, and what OS you're working in, there may be several automation options for sending keys, but most of them won't be able to find and select your text field. You'd have to position the cursor yourself, and then use an automation tool to just push the keys for you.

If you're on Windows, PyWinAuto is the favorite choice of several of my co-workers. It has a simple but reliable API for doing these kinds of basic automated tasks.

Chris Jaynes
  • 2,868
  • 30
  • 29