You can use the Win32 MapVirtualKey API function, which maps a virtual key to a bunch of values, one of which is a character value. MapVirtualKey seems to be using the currently installed keyboard layout (this is not documented). To use the specified layout, you can use MapVirtualKeyEx.
MapVirtualKey does not take into account whether Shift is pressed or not. To easily get information, if you press Shift, you can use GetKeyState (unfortunately, the WinRT command did not make it easier to get the state of modifier keys).
Here is an example of how to translate a virtual key into a symbol:
[DllImport("user32.dll")] private static extern uint MapVirtualKey(uint uCode, uint uMapType); [DllImport("user32.dll")] private static extern short GetKeyState(uint nVirtKey); private const uint MAPVK_VK_TO_CHAR = 0x02; private const uint VK_SHIFT = 0x10; private char TranslateVirtualKeyIntoChar(VirtualKey key) { char c = (char)MapVirtualKey((uint)key, MAPVK_VK_TO_CHAR); short shiftState = GetKeyState(VK_SHIFT); if (shiftState < 0) {
Update
Unfortunately, this solution does not apply to Windows Store applications that must be certified. The certificate fails because MapVirtualKey and GetKeyState APIs are used. It also means that this solution will most likely not work under WinRT.
source share