简体   繁体   English

具有不同键盘布局的 MapVirtualKeyExA

[英]MapVirtualKeyExA with different keyboard layouts

I try to use MapVirtualKeyExA with different keyboard layouts.我尝试使用具有不同键盘布局的MapVirtualKeyExA This function always returns English letters, no matter what keyboardlayout parameter I pass.无论我传递什么键盘布局参数,此函数始终返回英文字母。

在此处输入图像描述

I use console app and get layout by GetKeyboardLayout :我使用控制台应用程序并通过GetKeyboardLayout获取布局:

 HWND foreground = GetForegroundWindow();
 DWORD threadId;
 HKL keyboardLayout;
 if (foreground) 
 {
    threadId = GetWindowThreadProcessId(foreground, NULL);
    keyboardLayout = GetKeyboardLayout(threadId); 
 }

Convert keyCode to char :keyCode转换为char

char crrKey;
bool lower = ((GetKeyState(VK_CAPITAL) & 0x0001) != 0);
if ((GetKeyState(VK_SHIFT) & 0x1000) != 0 || (GetKeyState(VK_LSHIFT) & 0x1000) != 0 || (GetKeyState(VK_RSHIFT) & 0x1000) != 0) 
{
    lower = !lower;
}
crrKey = MapVirtualKeyExA(key, MAPVK_VK_TO_CHAR, keyboardLayout);
cout << keyboardLayout << ": " << crrKey << endl;
if (!lower) 
{
    crrKey = tolower(crrKey);
}
file << char(crrKey);

I want that when changing the language (Windows + Space) VirtualKey is mapped to the new language.我希望在更改语言(Windows + Space)时将 VirtualKey映射到新语言。 What am I doing wrong?我究竟做错了什么?

我建议您可以使用ToUnicodeEx API将指定的虚拟键代码和键盘状态转换为相应的 Unicode 字符或字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM