To know which key is pressed, you don't need to convert anything to ASCII. By the way, keep in mind that .NET internally supports Unicode UTF-16,
not ASCII.
What you have in
lParam.vkCode
in not directly related to character codes; this is a "virtual code" of the key press.
Here is the table of those codes:
http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx[
^].
You can take this table in C# code, make a enumeration type out of it and use. Actually, you should get the same enumeration as
System.Windows.Input.Key
or
System.Windows.Forms.Keys
. You can use one of those types and type cast.
[EDIT]
Answering a follow-up question: "Would you like to explain me about the way how to convert Virtual code to Unicode?"
There is no such conversion. In you case you don't need it, you need to compare just keys.
Let me explain.
Virtual code carry no information about Unicode characters because this information is simply absent. The character is not yet generated. Virtual key codes represent the keys on the physical keyboard device, not character. For example, if you press the key marked as '{', later on a character will be generated, but this character can be '{', '[' or some non-ASCII character, depending on several factors: status of modifier keys (like Shift), key toggles (like Capital, Caps Lock), installed and activated keyboard layout, Unicode or non-Unicode mode of the application, current input language, input method, current UI culture of the application and, finally, local processing of the events in a currently active application All that factors are taken into account
by OS to generate a character.
At the moment you receive a virtual key code, this information — in general case — is not available. You only got an information of the physical key pressed. Now, even though alphabetical key, say English 'A' has the same integer code point value as the virtual key marked as 'A', it does not mean a character 'A' will be generated. A generated character (if any) depends on the factors I listed in the above paragraph. Many key generate no characters at all and are always used in their virtual key mode form: F1 to F12, Alt, Shift, VolumeMute, VolumeDown — many of them. Please see the table I referenced above.
Generally, there are several layers of keyboard processing, one based on another: scan code, OEM code, virtual key code. Virtual key code in not the "most hardware" level. For example, if contains mouse event which are unrelated from the hardware stand point.
—SA