从窗口中提取键盘布局
好吧,这是一个有点奇怪的问题。
我们有一个触摸屏应用程序(即没有键盘)。 当用户需要输入文本时,应用程序会显示虚拟键盘 - 在 WinForms 中手工构建。
为每种新语言手工制作这些东西是一件很麻烦的事。 我认为 Windows 必须将键盘布局信息隐藏在某个 dll 中的某个位置。 有什么办法可以从窗口中获取这些信息吗?
欢迎其他想法(我认为至少从 xml 文件生成东西比在 VS 中手动生成更好)。
(注意:话虽如此,我注意到有一个日语键盘、状态机等等......,所以 XML 可能还不够)
更新:关于这个主题的相当不错的系列(我相信) 这里
OK, this is a slightly weird question.
We have a touch-screen application (i.e., no keyboard). When users need to enter text, the application shows virtual keyboard - hand-built in WinForms.
Making these things by hand for each new language is monkey work. I figure that windows must have this keyboard layout information hiding somewhere in some dll. Would there be anyway to get this information out of windows?
Other ideas welcome (I figure at least generating the thing from a xml file has got to be better than doing it by hand in VS).
(Note: having said all which, I note that there is a Japanese keyboard, state machine and all..., so XML might not be sufficient)
UPDATE: pretty good series on this subject (I believe) here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Microsoft Keyboard Layout Creator 可以加载系统键盘并将其导出为 .klc 文件。 由于它是用 .NET 编写的,因此您可以使用 Reflector 来查看它是如何做到这一点的,并使用反射来驱动它。 这是Windows 8 中 187 键盘的 .klc 文件的 zip 文件 使用以下 C# 代码创建。 请注意,我最初是为 Windows XP 编写的,现在使用 Windows 8 和屏幕键盘,它真的很慢,并且似乎使任务栏崩溃:/但是,它确实有效:)
基本上,它获取了所有系统上的键盘,然后对于每个键盘,将其加载到 MSKLC 中,设置“另存为”文件名,说明是否已配置自定义键盘属性,然后模拟单击“文件”->“文件”。 保存菜单项。
Microsoft Keyboard Layout Creator can load system keyboards and export them as .klc files. Since it’s written in .NET you can use Reflector to see how it does that, and use reflection to drive it. Here's a zip file of .klc files for the 187 keyboards in Windows 8 created using the below C# code. Note that I originally wrote this for Windows XP, and now with Windows 8 and the on-screen keyboard, it is really slow and seems to crash the taskbar :/ However, it does work :)
Basically, it gets a list of all the keyboards on the system, then for each one, loads it in MSKLC, sets the "Save As" filename, lies about whether it's already configured the custom keyboard properties, and then simulates a click on the File -> Save menu item.
众所周知,MSKLC 无法忠实地导入和导出数据。 重现 Windows 提供的所有 .DLL 文件的键盘布局,尤其是 Windows 8 和 Windows 中的文件。 多于。 如果您无法从这些文件中提取任何有意义或有用的信息,那么知道这些文件在哪里也没有任何好处。
Michael Kaplan 在他的博客(他是 MSKLC 的开发人员)上记录了这一点,我看到您已在上面链接到该博客。
当 MSKLC 遇到任何它不理解的内容时,该部分就会被删除。
使用 MSKLC 提取布局适用于大多数键盘,但也有少数键盘,即切诺基键盘、日文键盘和日文键盘。 韩语键盘(仅举几例,我不确定还有多少)——提取的布局将无法准确或完整地反映实际使用情况和使用情况。 键盘的功能。
切诺基键盘具有 MSKLC 不支持的连锁死键。 远东键盘有 MSKLC 不知道的修饰键 - 这意味着整个图层/转换状态都丢失了!
Michael Kaplan 提供了一些代码并解开了 MSLKC 的一些秘密以及可用于绕过其中一些限制的随附软件,但它需要大量手动操作 - 这正是您想要避免的! 另外,Michael 的目标是创建具有 MSKLC 无法创建或理解的功能但可以在 Windows 中工作的键盘(这与 OP 试图实现的目标相反)。
我确信我的解决方案来得太晚了,无法对OP有用,但也许它将来会对处于类似情况的人有所帮助。 这就是我的希望,也是发帖的原因。
到目前为止,我所做的只是解释其他答案是不够的。 即使是最好的人也不会也不可能完全& 准确地再现所有 Windows 的本机键盘并将它们渲染到 KLC 源文件中。 这真的很不幸,这当然不是其作者的错,因为这是一段非常聪明的代码/脚本! 值得庆幸的是剧本和 源文件(其链接可能仍然有效,也可能不再有效)是有用的& 对大多数 Windows 键盘以及 MSKLC 创建的任何自定义键盘有效。
具有 MSKLC 不支持的高级功能的键盘是由 Windows DDK 创建的,但这些功能没有正式记录。 尽管人们可以通过研究 MSKLC 提供的源文件来了解很多关于它们的潜力。
遗憾的是,我能提供的唯一解决方案是名为 KbdEdit 的第三方付费软件。 我相信这是目前唯一可用的解决方案,实际上能够忠实地解码和解码。 重新创建任何 Windows 提供的键盘 - 尽管有一些高级功能甚至无法重现(例如执行特殊母语功能的组合键/热键;例如:Ctrl+CapsLock 激活 KanaLock(日语修饰层) KbdEdit 确实忠实地再现了 MSKLC 剥离的修饰层,但如果您没有带有假名锁定键的日语键盘,它只是不支持激活该转换状态的替代方法。将键盘上的按键转换为假名键(也许是 Scroll Lock?)。
甚至都不适用于屏幕键盘。
KbdEdit 是一个非常强大且令人惊叹的工具,它 我付了钱!(对于几乎任何其他付费软件,我都不会这么说……)
尽管 KbdEdit 是第三方软件,但它只需要创建键盘,而不需要使用它们。 它创建的所有键盘都可以在任何 Windows 系统上本地运行,无需安装 KbdEdit。
它支持多达 15 种修改器状态和三个附加修改键,其中一个是可切换的,如 CapsLock。 它还支持链接死键,并重新映射大多数键盘上的任何键。
It is a fairly well-known fact that MSKLC is unable to faithfully import & reproduce keyboard layouts for all of the .DLL files supplied by Windows–especially those in Windows 8 & above. And it doesn't do any good to know where those files are if you can't extract any meaningful or helpful information from them.
This is documented by Michael Kaplan on his blog (he was a developer of MSKLC) which I see you have linked to above.
When MSKLC encounters anything it does not understand, that portion is removed.
Extracting the layout using MSKLC will work for most keyboards, but there are a few–namely the Cherokee keyboard, and the Japanese & Korean keyboards (to name a few, I'm not sure how many more there are)–for which the extracted layout will NOT accurately or completely reflect the actual usage & features of the keyboard.
The Cherokee keyboard has chained dead keys which MSKLC doesn't support. And the far Eastern keyboards have modifier keys which MSKLC isn't aware of–that means entire layers/shift states which are missing!
Michael Kaplan supplies some code and unlocks some of the secrets of MSLKC and the accompanying software that can be used to get around some of these limitations but it requires a fair amount of doing things by hand–exactly what you're trying to avoid! Plus, Michael's objectives are aimed at creating keyboards with features that MSKLC can not create or understand, but which DO work in Windows (which is the opposite of what the OP is trying to accomplish).
I am sure that my solution comes too late to be of use to the OP, but perhaps it will be helpful in the future to someone in a similar situation. That is my hope and reason for posting this.
So far all I've done is explain that the other answers are insufficient. Even the best one will not and can not fully & accurately reproduce all of Windows' native keyboards and render them into KLC source files. This is really unfortunate and it is certainly not the fault of its author because that is a very clever piece of code/script! Thankfully the script & the source files (whose link may or may not still work) is useful & effective for the majority of Windows' keyboards, as well as any custom keyboards created by MSKLC.
The keyboards that have the advanced features that MSKLC doesn't support were created by the Windows DDK, but those features are not officially documented. Although one can learn quite a bit about their potential by studying the source files provided with MSKLC.
Sadly the only solution I can offer is 3rd party, paid software called KbdEdit. I believe it is the only currently available solution which is actually able to faithfully decode & recreate any of the Windows supplied keyboards–although there are a few advanced features which even it can not reproduce (such as keys combinations/hotkeys which perform special native language functions; for example: Ctrl+CapsLock to activate KanaLock (a Japanese modifier layer). KbdEdit DOES faithfully reproduce that modifier layer which MSKLC with strip away, it just doesn't support this alternate method of activating that shift state if you don't have a Japanese keyboard with a Kana lock key. Although, it will allow you to convert a key on your keyboard to a Kana key (perhaps Scroll Lock?).
Fortunately, none of those unsupported features are even applicable to an on-screen keyboard.
KbdEdit is a really powerful & amazing tool, and it has been worth every penny I paid for it! (And that's NOT something I would say about virtually any other paid software…)
Even though KbdEdit is 3rd party software, it is only needed to create the keyboards, not to use them. All of the keyboards it creates work natively on any Windows system without KbdEdit being installed.
It supports up to 15 modifier states and three addition modifier keys, one which is togglable–like CapsLock. It also supports chained dead keys, and remapping any of the keys on most any keyboard.
为什么不使用屏幕键盘(osk.exe)? 看来你重新发明了轮子。 而且不是最简单的!
Why don't you use the on-screen keyboard (osk.exe)? Looks like you re-inventing the wheel. And not the easiest one!
我知道这些 DLL 文件的路径在哪里:
在注册表中,您会看到:
每个分支都有一些值,例如
"Layout File"="KBDSP.dll"
。 根目录是和
这些是所有键盘布局文件所在的位置。 例如,
KBDUS.dll
表示“美国键盘”。我尝试用 MSKLC 制作的自定义 DLL 替换该 DLL 文件,发现它在“语言”-“输入法”-“预览”中自动加载布局映射图像:
所以我们知道该映射位于 DLL 中。
I know where are these DLL files' path:
In your registry, you see:
where each branch has some value like
"Layout File"="KBDSP.dll"
. The root directory isand
Those are all the keyboard layout files are located. For example,
KBDUS.dll
means "keyboard for US".I tried to substitute the DLL file with my custom DLL made by MSKLC, and I found it loads the layout mapping images automatically in the "Language" - "input method" - "preview":
So we know that the mapping is there in the DLL.
请检查以下 Windows API
检查MSDN 此处
Please check following Windows API
Check MSDN here