admin管理员组

文章数量:1330627

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>

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>
Share Improve this question asked May 19, 2012 at 12:57 fart-y-goerfart-y-goer 7393 gold badges8 silver badges27 bronze badges 4
  • 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 Commented May 19, 2012 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 Commented May 19, 2012 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 Commented May 19, 2012 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 Commented May 19, 2012 at 13:06
Add a ment  | 

2 Answers 2

Reset to default 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.

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.

本文标签: javascriptJquery Barcode Scanner IntegrationStack Overflow