MapVirtualKeyexa带有不同键盘布局

发布于 2025-01-31 22:07:14 字数 1164 浏览 2 评论 0 原文

我尝试使用不同的键盘布局使用 mapVirtualKeyexa 。无论我通过哪种键盘layout参数,此功能总是返回英文字母。

我使用控制台应用程序,并通过 getKeyboardLayout 获得布局:

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

转换 keycode to char> 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);

我希望在更改更改时语言(Windows + Space)VirtualKey 映射到新语言。我在做什么错?

I try to use MapVirtualKeyExA with different keyboard layouts. This function always returns English letters, no matter what keyboardlayout parameter I pass.

enter image description here

I use console app and get layout by GetKeyboardLayout:

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

Convert keyCode to 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. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-07 22:07:14

I suggest you could use ToUnicodeEx API to translate the specified virtual-key code and keyboard state to the corresponding Unicode character or characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文