I can't translate a character according to the set keyboard layout.Tried several variants, but it doesn't work.
I enter the Russian character "Л" and the output is getting the English character "K". There is no translation. The input should be "Л" and the output should be "Л".
First version:
std::wstring StandardKeyToStringW(DWORD VKey)
{
static WCHAR name[32] = { 0 };
static BYTE kbState[256] = { 0 };
DWORD idThread;
GetWindowThreadProcessId(GetForegroundWindow(), &idThread);
long code = MapVirtualKeyExW(VKey, MAPVK_VK_TO_VSC, GetKeyboardLayout(idThread)) << 16;
GetKeyboardState(kbState);
ToUnicode(VKey, code, kbState, name, 32, 0);
return name;
}
Second version:
std::wstring StandardKeyToStringW(DWORD VKey)
{
static WCHAR name[32] = { 0 };
DWORD idThread;
GetWindowThreadProcessId(GetForegroundWindow(), &idThread);
long code = MapVirtualKeyExW(VKey, MAPVK_VK_TO_VSC, GetKeyboardLayout(idThread)) << 16;
GetKeyNameTextW(code, name, 32);
return name;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…