I've got a small event handler to process all keys pressed by the user or delivered by barcode scanner:
public void KeyDownSink(object sender, System.Windows.Input.KeyEventArgs e)
{
_textRead.Append(e.Key);
}
private StringBuilder _textRead = new StringBuilder();
The variable _textRead
should collect all characters pressed. I'm only interested in keys which produce a printable output (a-z,0-9, !"ยง$%& and so on). If the user presses e.g. Ctrl this will add the string LeftCtrl to _textRead
, so I want to skip this key.
How to filter out control keys like Ctrl, Shift, , Alt... in an elegant way?
I know I can achieve this with a lot of conditional statements (if e.Key == Key.Ctrl
) but I hope to find a nicer way.