C# KeyDown alphanumeric culture dependent !
How to determine if the pressed Key
is an alphabetica开发者_开发问答l 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;
}
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;
}
精彩评论