2

I have a barcode scanner works as HID device. Everytime a barcode scans it goes directly to windows keyboard, for example if I open notepad I can see the barcode typed there.

As far as I know programmatically is it possible to to read HID data from your HID devices.

But what happens if the user is already on a form with a text edit control? The scanned code will go inside the text box.

Can you block incoming text and make a background-only processing?

Can you explain the theory please?

Filburt
  • 17,626
  • 12
  • 64
  • 115
user1008476
  • 31
  • 1
  • 1
  • 2
  • 1
    Do you really want to know the background theory of how the devices work, or do you just want to intercept the barcode before it gets to the text box? They're two very different questions. – Rob Kennedy Jun 04 '12 at 10:38

3 Answers3

2

See if your barcode scanner can emulate a serial port and just read the data directly from the the serial port into your app.

That is cleaner and less expensive then a global keyboard hook. When I was looking into this awhile ago I found that most USB barcode scanners can emulate a serial port, it's a cinch to read serial port data in most programming languages. I happened to be doing mine in Java, I posted an example in answer to this question actually.

Community
  • 1
  • 1
egerardus
  • 11,316
  • 12
  • 80
  • 123
2

You can set up your scanner to use USB-HID(POS) setting. Your datasheet of barcode settings for the scanner device should have it. I use this project to test my scanners. http://www.codeproject.com/Articles/18099/A-USB-HID-Component-for-C

reas
  • 379
  • 1
  • 6
  • I'd just like to clarify that after so much looking around and seeing virtually everyone recommend serial over USB as being "cleaner" and less "expensive" and not understanding that there's a hot pluggable solution that can work wonders (fsck you COM port with your unhandled disconnects and refuse to share your ports!), I finally found your answer! – Paul-Sebastian Manole Aug 01 '13 at 20:40
0

Sure, just capture keypresses before they are handled by the control and suppress normal handling of the events. In VB.NET you might override the OnKeyPress method in your form and set KeyPreview to true, for example.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • 1
    I just want to know the theory how to make it work not the entire HID theory. The OnKeyPress, how should I know which one is real keyboard and the barcode scanner? – user1008476 Jun 04 '12 at 12:00
  • 1
    You cannot distinguish the two. For the system at that level it's just a keyboard event and *both your actual keyboard and the scanner are keyboards, as far as the OS is concerned*. – Joey Jun 04 '12 at 12:57
  • I am trying to make it work as HID but I cannot get exclusive access disabling the automatic typing of barcode inside the text fields. This is my main problem. Because when user types something in the text field example adding a new member, the user can pass the card on the barcode and the number will be typed in the text edit. Can you help on this? – user1008476 Jun 04 '12 at 13:50