0

I'm trying to identify non-printable characters and replace them with printable characters when scanning a barcode. Currently I'm getting some difficulties to identify all non-printable characters returning from the barcode scanner.

if (e.Key == Key.NumLock) // this is working
{
    txtBarcode.Text += "<AI>";
    txtBarcode.SelectionStart = i + 5;
    e.Handled = true;
}

What I want to do is without checking is it a NumLock character, I need to check if it a special character like Numlock, Tab etc.. and then replace it with "AI" string. In other words, Commonly check If it is a non-printable character or not. And I need to do this on KeyDown event.

if (e.Key == Key.IsSpecialKey || e.Key == Key.IsNonPrintableKey) // this is what I want
{
    txtBarcode.Text += "<AI>";
    txtBarcode.SelectionStart = i + 5;
    e.Handled = true;
}
Ravi Rajindu
  • 380
  • 2
  • 6
  • 23
  • I think https://stackoverflow.com/questions/5825820/how-to-capture-the-character-on-different-locale-keyboards-in-wpf-c/5826175#5826175 can help you... If you checks the return value of ```GetCharFromKey``` – Ryu Nov 19 '20 at 05:58
  • You might use the [KeyConverter](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.keyconverter?view=net-5.0) class and try to convert `e.Key` to a string. This will throw an exception if the key does not represent a character. To distinguish printable from non-printanble characters use the relevant `char.Is...` methods – Klaus Gütter Nov 19 '20 at 06:03

0 Answers0