views:

150

answers:

1

How to determine if the pressed Key is an alphabetical key regard to the culture specific keys:

e.g.:

'[' = 'ú' = 'ü' ... is the same key but with different value on different language Keyboards.

I've tried to compare the ordinal key value: (int)e.Key >= 0x20E ..and <= .. but it does not work well, as modifier keys have sometimes same ordinal codes.

Any idea? Thanks

EDITED:

Hmm and how about this ?

System.Text.RegularExpressions.Regex objAlphaNumericPattern = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
            if (!objAlphaNumericPattern.IsMatch(e.Key.ToString()))      
            {
                lp.IsDropDownOpen = true;
            }
A: 

Is char.IsLetter method helpful in your case?

char.IsLetter('['); //Return false
char.IsLetter('ú'); //Return true

With your sample, we can write:

if (!char.IsLetterOrDigit((char)e.Key))
{
    lp.IsDropDownOpen = true;
}
Gregg
e.Key is a virtual key code, not a char. Although for ASCII characters it will usually be the same value, it's not true as soon as you're outside the 0-127 range
Thomas Levesque