0

I have a bar code scanner that presents itself as a USB-HID keyboard.

How do I capture scanned bar codes in my c# WPF application, if the app currently does not have focus?


When a barcode is scanned, the scanner sends one or more configurable prefix keypress events, then the barcode itself, then some postfix keypresses.

If the application has focus, I can use the prefix hotkeys to focus a specific textbox; then the barcode is automatically entered into this textbox.

If the application does not have focus, how can I receive the barcode?

I could register a global hotkey via pInvoking RegisterHotkey from User32.dll, as outlined e.g. here:

But how do I capture the following keyboard events containing the bar code?

I am a little dubious about this approach as well, is there a simpler way to capture a string prefixed by a specific hotkey, without having focus?

Community
  • 1
  • 1
HugoRune
  • 13,157
  • 7
  • 69
  • 144
  • Try this: http://stackoverflow.com/questions/7164055/c-sharp-and-usb-hid-devices – Moby Disk Jan 29 '15 at 15:37
  • That looks like it might work, but I would prefer a solution that did not involve an entire custom usb driver library, hopefully there is a simpler way to capture a couple key presses. – HugoRune Jan 29 '15 at 16:43
  • It should not require a custom USB driver library. But you will need to rely on Windows API calls. http://stackoverflow.com/questions/3655023/how-do-i-read-input-from-a-usb-hid-device – Moby Disk Jan 29 '15 at 18:41

0 Answers0