<p>I am trying to map a virtual keycode to a char.</p>

<p>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.</p>

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

<p>Do you know the answer to the question?</p>

Yes, I did use the
```
MapVirtualKey
```
method. But I was expecting more details on how to use it: what
```
DllImport
```
directive to use, what
```
enum
```
is specific for mapping to characters, etc.
I don't like these answers where you google for like 5 seconds and then just suggest a solution: the real challenge is to put all the pieces together and not have to waste your time with tons of sample-less MSDN pages or other coding forums in order to get your answer. No offense plinth, but your answer (even good) was worhtless since I had this answer even before posting my question on the forum!
So there you  go, I am going to post what I was looking for - an out-of-the-box C# solution:
1- Place this directive inside your class:
```
```
[DllImport("user32.dll")]
static extern int MapVirtualKey(uint uCode, uint uMapType);
```
```
2- Retrieve your char like this:
```
```
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)      
  {
     const int WM_KEYDOWN = 0x100;

     if (msg.Msg == WM_KEYDOWN)
     {            
        // 2 is used to translate into an unshifted character value 
        int nonVirtualKey = MapVirtualKey((uint)keyData, 2);

        char mappedChar = Convert.ToChar(nonVirtualKey);
     }

     return base.ProcessCmdKey(ref msg, keyData);
  }
```
```
Thanks for caring... and enjoy!