I am handling the PreviewTextInput event on my window to handle swipes from a magnetic card reader. I handle the event on the window, so that it does not matter which individual control is focused.
Once the handler determines a swipe has started (a '%' or ';' character is input), it handles all events until the swipe is finished. This system generally works quite nicely, with a few important exceptions:
When a space character (and possibly a
character) are input from the reader, they are not handled by PreviewTextInput, but are sent directly into whatever control is focused. Oddly enough, the handler does receive
characters. This causes undesired behavior.
What I want is a way to capture all key events at the window level, and have an opportunity to handle them if I want to. I have tried PreviewKeyDown and found it a bit cumbersome to use, and to get char values from. PreviewTextInput is much nicer because I can simply read the Text property.
Is there a reason PreviewTextInput does not handle certain characters? Is there any comparable method to get all events, including spaces?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…