Determine is key pressed is alphanumeric in Windows Runtime

.net, c#, windows-runtime

Solution

The `KeyRoutedEventArgs` contains a `Key` value which is a VirtualKey.

You can simply test if the `Key` is within the codes you want to support from this list.

For example:

private void MyKeyDown(object sender, KeyRoutedEventArgs e)
{
    int keyValue = (int)e.Key;
    if ((keyValue >= 0x30 && keyValue <= 0x39) // numbers
     || (keyValue >= 0x41 && keyValue <= 0x5A) // letters
     || (keyValue >= 0x60 && keyValue <= 0x69)) // numpad
    {
        // do something
    }
}

Problem

I'm working on an app for `Windows 8`. I'm trying to determine if a key pressed is alphanumeric. The `KeyRoutedEventArgs` class doesn't seem to provide any helpers. Is there something I'm overlooking? What is the best way to determine if the user entered a letter or number?

Original source