.
Summary
C# Signature:
[DllImport("user32.dll")]
static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte []
lpKeyState, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff,
int cchBuff, uint wFlags, IntPtr dwhkl);
User-Defined Types:
None.
Notes:
Convert a ASCI Character into Unicode Character with the Keyboard Layout
Tips & Tricks:
Please add some!
Sample Code:
[DllImport("user32.dll")]
static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte [] lpKeyState, [Out, MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags, IntPtr dwhkl);
[DllImport("user32.dll")]
static extern bool GetKeyboardState(byte [] lpKeyState);
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll")]
static extern IntPtr GetKeyboardLayout(uint idThread);
public static string VKCodeToUnicode(uint VKCode)
{
System.Text.StringBuilder sbString = new System.Text.StringBuilder();
byte[] bKeyState = new byte[255];
bool bKeyStateStatus = GetKeyboardState(bKeyState);
if (!bKeyStateStatus)
return "";
uint lScanCode = MapVirtualKey(VKCode,0);
IntPtr HKL = GetKeyboardLayout(0);
ToUnicodeEx(VKCode, lScanCode, bKeyState, sbString, (int)5, (uint)0, HKL);
return sbString.ToString();
}
Alternative Managed API:
Do you know one? Please contribute it!
Documentation
The ToUnicodeEx API
11/1/2009 3:29:18 PM - -83.145.242.8
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).