C# How to translate virtual keycode to char?

Horas picture Horas · Nov 25, 2008 · Viewed 94.7k times · Source

I am trying to map a virtual keycode to a char.

My code uses ProcessCmdKey to listen to WM_KEYDOWN which gives me access to the key pressed. For example, when I press single quote I get a key of 222 which I want to have it mapped to keychar 39 which represents... you guessed it... single quote.

My dev context is: - .net Framework 2.0 - UserControl placed in a lot of places

Do you know the answer to the question?

Answer

Powerlord picture Powerlord · Nov 26, 2008

Isn't that what the System.Windows.Form.KeysConverter class is for?

KeysConverter kc = new KeysConverter();
string keyChar = kc.ConvertToString(keyData);