How to convert a virtual-key code to a character according to the current keyboard layout?

Viewed 21525

I have browsed several earlier questions about this, and the best answer I found so far is something like this:

(char) WinAPI.MapVirtualKey((uint) Keys.A, 2)

However, this doesn't work in two ways:

  • It always returns capital letters. For Keys.A I expect to get the character a, while for Keys.A | Keys.ShiftKey I expect to get A; however, I seem to get A for both.

  • It doesn't seem to take keyboard layouts into account. For example, for Keys.OemMinus I always seem to get the character -, even if the current keyboard layout is German, where I expect this key to return ß.

What is the correct solution for this?

3 Answers
Related