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:
- How can I register a global hot key to say CTRL+SHIFT+(LETTER) using WPF and .NET 3.5?
- Global hotkeys in WPF working from every window
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?