OnKeyDown

  • Thread starter Thread starter Jaga
  • Start date Start date
J

Jaga

If I trap the event OnKeyDown in a Control, I become a
System.Windows.Forms.KeyEventArgs.
How can I determine whether the key in the KeyEventArgs a printable char is?

Thanks in advance

Jaga
 
Hi,
I believe printable ASCII is between 32 and 127, inclusively.
It is not so easy though. What you get from KeyEventArgs are the scan codes
of the keys. Some of the keys can represent printable chars in combinations
with other keys and non-printable in other situations. For example the
numeric keypad. Its keys can generate prinatable chars if NumLock is on and
non-printables if it is off. Some noninglish keybaord layouts use so-called
dead keys and then one or more successive keys may represent one character
and so on.
That's why for this purposes OnKeyPress event should be used instead. With
this event you recieve the code of the character instead of the scan code of
the key. Having the character code one have a bunch of options. With *char*
objects one can use Char.IsXXXX methods to find out in what category the
char falls in. For finest char categorization one can use GetUnicodeCategory
method.
 
Thank you Stoitcho.
You are of course right. The OnKeyPress event were the best.
Unfortunatelly, it is too late. I have to trap the OnKeyDown event or
PreProcessMessage.
 
Back
Top