I have an application that can receive key strokes from a barcode scanner (which to Windows just looks like a USB keyboard).
My requirement is for the user to be able to use the barcode scanner anywhere in the application (any window, any tab) and have it react accordingly. I already have a version of this working by monitoring for PreviewTextInput
events in my App.xaml.cs
and firing off my own custom BarcodeArrived
event. The problem with this is that if the user has put focus on a control that does not accept Text Input, then PreviewTextInput never fires.
PreviewKeyDown
does always fire, but the data it presents is ugly and I can't seem to find anyway of translating KeyDown events to a normalized string. I found a Stack Overflow article at "Convert received keys in PreviewKeyDown to a string" seemed promising, but it does not appear that I can wire this in my App.xaml.cs (no dependency object).
Any thoughts or suggestions would be great. Or, as an alternative, at least a way of detecting which keyboard the input is coming from, at which point using PreviewKeyDown
might be a viable option because I can assume a "dumbed down" input stream.