如何创建键盘列表.从HKL中提取KLID? [英] How to create a list of Keyboards. Extract KLID from HKL?

查看:60
本文介绍了如何创建键盘列表.从HKL中提取KLID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 10/C ++/Win32

Windows 10 / C++ / Win32

我需要列出已安装"的键盘.

I need to make a list of 'installed' Keyboards.

列表"中的组件必须包含:

The components of my 'list' needs to contain:

  • 键盘的HKL.
  • 键盘的KLID.
  • 从以下位置获得的注册表值的值:
  • HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \键盘布局
  • 示例: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Keyboard Layouts \ 00000409
  • 值:布局文件
  • 值:布局文字

我知道枚举键盘的唯一方法是通过 GetKeyboardLayoutList(),它返回HKL的列表.

The only way I am aware of enumerating Keyboards is via GetKeyboardLayoutList(), which returns a list of HKL's.

适用于标准"键盘的方法(HKL的04090409、04070407等).

Methodology which works for 'standard' keyboards (HKL's 04090409, 04070407,..).

TCHAR Buffer[50];
TCHAR Buffer2[50];
HKL LoadedKeyboardLayout;

// Hkl: 04090409
_stprintf_s(Buffer, (sizeof(Buffer)/sizeof(TCHAR)), _T("%08X"), (((UINT)Hkl >> 16) & 0xFFFF));
// Buffer: "0000409"
LoadedKeyboardLayout = LoadKeyboardLayout(Buffer, (UINT)0);
// It Loads

ActivateKeyboardLayout(LoadedKeyboardLayout, KLF_SETFORPROCESS);
// It Activates

GetKeyboardLayoutName(Buffer2); 
// Buffer2: "00000409"

// I can now fish the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00000409

当设备标识符"不是0000时,此功能不起作用.

This DOES not work when the 'device identifier' is NOT 0000.

来自 LoadKeyboardLayout()文档:

要加载的输入语言环境标识符的名称.该名称是一个字符串,由语言标识符(低位字)的十六进制值和设备标识符(高位字)组成.例如,美国英语的语言标识符为0x0409,因此主要的美国英语布局被命名为"00000409".美国英语版式的变体(例如Dvorak版式)被命名为"00010409","00020409",依此类推.

The name of the input locale identifier to load. This name is a string composed of the hexadecimal value of the Language Identifier (low word) and a device identifier (high word). For example, U.S. English has a language identifier of 0x0409, so the primary U.S. English layout is named "00000409". Variants of U.S. English layout (such as the Dvorak layout) are named "00010409", "00020409", and so on.

如果创建了自定义"键盘,我发现不可能从自定义键盘HKL获取设备标识符".

If one creates a 'Custom' keyboard, I find it is impossible to get the 'device identifier' from the custom keyboards HKL.

例如:

  • 使用MKLCS创建自定义键盘.
  • 安装.
  • "KLID"将为"A0000409".
  • HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Keyboard Layouts \ a0000409
  • HKL为0xF0C00409(由 GetKeyboardLayoutList()生成的HKL列表中返回).
  • 要使用 LoadKeyboardLayout()加载键盘,需要输入'A0000409'.
  • 似乎无法从F0C00409创建A0000409.
  • 我还创建了没有MKLCS的自己的键盘布局.
  • 我随意将其命名为00060409.
  • HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Keyboard Layouts \ 00060409
  • 它的HKL是FFFE0409(由 GetKeyboardLayoutList()生成的HKL列表中返回).
  • 似乎无法从FFFE0409创建00060409.
  • Create a Custom Keyboard US with MKLCS.
  • Install it.
  • The 'KLID' will be 'A0000409'.
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\a0000409
  • The HKL will be 0xF0C00409 (as returned within the HKL list generated by GetKeyboardLayoutList()).
  • In order to load the keyboard with LoadKeyboardLayout(), one needs 'A0000409'.
  • It does not seem possible to create A0000409 from F0C00409.
  • I also created my own keyboard layout without MKLCS.
  • I arbitrarily named it 00060409.
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\00060409
  • It's HKL is FFFE0409 (as returned within the HKL list generated by GetKeyboardLayoutList()).
  • It does not seem possible to create 00060409 from FFFE0409.

话虽如此,一个人如何从HKL取得KLID?

With all of that said, how does one obtain a KLID from an HKL?

或者,还有其他方法可以创建已安装键盘的列表吗?

Or, is there another way I can go about creating my list of installed keyboards?

//================================================================2020年11月25日添加.

//================================================================ 11/25/2020 Addition.

谢谢丽塔.

似乎 GetKeyboardLayoutList()创建了已加载"键盘布局的列表.

It seems as if GetKeyboardLayoutList() creates a list of 'Loaded' keyboard layouts.

  • 系统加载的键盘布局,0x0409409,....
  • 通过MKLCS安装安装的键盘布局.

似乎以下注册表项中定义的所有键盘都将在启动时加载.

It seems that any Keyboards defined within the following registry keys will get loaded at boot.

  • HKEY_CURRENT_USER \键盘布局注意预载和替换"值.
  • HKEY_CURRENT_USER\Keyboard Layout Note the Preload and Substitute value's.

(请注意,注册表中还有许多其他键盘布局"键,不知道 HKEY_CURRENT_USER \ Keyboard Layout 是否是定义注册表项的实际注册表项PreLoad-替代.

(Note there are many other 'Keyboard Layout' keys spread around within the registry, so I am not sure if HKEY_CURRENT_USER\Keyboard Layout is the actual registry key that defines the PreLoad - Substitutes.

  • HKEY_USERS \ .DEFAULT \ Keyboard Layout
  • HKEY_USERS \ S-1-5-18 (我的用户帐户)
  • HKEY_LOCAL_MACHINE \ SYSTEM \键盘布局)
  • HKEY_USERS\.DEFAULT\Keyboard Layout
  • HKEY_USERS\S-1-5-18 (My User Account)
  • HKEY_LOCAL_MACHINE\SYSTEM\Keyboard Layout )

因此,毫无疑问,Rita的示例之所以有效,是因为她的 HKEY_CURRENT_USER \ Keyboard 布局包含以下条目:预载:1 d0010804

So there is no doubt in my mind that Rita's example works due to the fact that her HKEY_CURRENT_USER\Keyboard Layout contains the following entries: Preload: 1 d0010804

替代品:d0010804 a0000804

Substitutes: d0010804 a0000804

这些条目可能已经由MKLCS安装程序放在了那里?或通过设置"->时间"和添加"添加键盘的操作语言->单击首选语言->选项->添加键盘

The entries may have been put there by the MKLCS installer? Or perhaps the action of adding the keyboard via Settings->Time & Language->Click on Preferred Language->Options->Add a Keyboard

来自 ActivateKeyboardLayout()文档:

输入的语言环境标识符必须已通过先前对LoadKeyboardLayout函数的调用来加载.

The input locale identifier must have been loaded by a previous call to the LoadKeyboardLayout function.

由于实际上已经加载了a0000804(HKL:F0C00804),所以 ActivateKeyboardLayout()可行.

Since a0000804 (HKL: F0C00804) is actually already loaded ActivateKeyboardLayout() works.

由于我的KLID:00060409没有在任何X \ Keyboard Layout预加载和替换中引用我必须亲自调用 LoadKeyBoardLayout(L"00060409"),以使其出现在 GetKeyboardList() HKL中.

Since my KLID: 00060409 is not referenced within any of the X\Keyboard Layout Preload and Substitutes I must physically call LoadKeyBoardLayout(L"00060409") in order for it to appear within the GetKeyboardList() HKL's.

再次感谢丽塔.

推荐答案

人们如何从HKL获得KLID?

how does one obtain a KLID from an HKL?

似乎没有开箱即用的直接方法即可实现.

There seems no direct method out of box to achieve it.

一种解决方法是检索HKL列表,然后通过 HKL 激活布局,然后获取其 KLID .以下是一个示例:

A workaround is retrieving a list of HKLs, then active a layout via a HKL, then get its KLID. The following is an example:

int cnt = GetKeyboardLayoutList(sizeof(hklArr)/sizeof(hklArr[0]), hklArr);
if(cnt > 0)
{
    printf("keyboard list: \n");
    for (UINT i = 0; i < cnt; i++)
    {
        printf("%x\n", (LONG_PTR)hklArr[i]);
        if (ActivateKeyboardLayout(hklArr[i], KLF_SETFORPROCESS))
        {
            WCHAR pName[KL_NAMELENGTH];
            if (GetKeyboardLayoutName(pName))
            {
                wprintf(L"layout name (KLID): %s\n", pName);
            }
        }
    }
}

结果如下:

更新:

更新2 :分享我的创建和安装步骤.

Update 2: Share my creating and installing steps.

我使用Keyboard Layout Creator 1.4.

I use Keyboard Layout Creator 1.4.

  1. 加载现有键盘以进行测试.(您可以基于它进行修改,也可以完全创建自己的.)

  1. 有效并测试键盘以确保它可以按预期工作.然后构建DLL和安装程序包.

  1. 运行由步骤2生成的setup.exe.安装完成后,您将在注册表中看到相关的预加载键盘布局项.

这篇关于如何创建键盘列表.从HKL中提取KLID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆