如何确定另一个进程(Windows)的键盘布局?
我正在开发一个需要记录和回放击键的程序。 主进程作为服务运行,因此需要一个配置程序来记录击键。
当系统默认键盘布局是(比如)英语,而用户当前的键盘布局是(比如)德语时,就会出现问题。 用户在配置界面中输入“ü”字符,该字符被适当记录和存储。
现在,用户运行记事本并尝试回放击键,这是由服务的子项完成的。 当转换输入以传递给 SendInput
时,我们调用 VkKeyScan
,然后它告诉我们无法在此键盘上重现该字符(请记住默认键盘布局是英语)。
我真正想做的是同步服务的键盘布局和当前的前台应用程序,以便服务可以重现用户可以使用键盘的任何字符。 GetKeyboardLayout
仅适用于当前进程。 它必须在 32 位和 64 位上运行,因此消息挂钩......不是首选:)。
I'm working on a program that needs to record and play back keystrokes. The main process runs as a service, so it needs a configuration program to record the keystrokes.
The problem comes when the system default keyboard layout is (say) English, and the user's keyboard layout of the moment is (say) German. The user enters a 'ü' character into the configuration interface, which is duly recorded and stored.
Now the user runs Notepad and tries to play the keystroke back, which is done by a child of the service. When transforming input to pass to SendInput
, we call VkKeyScan
, which then tells us there's no way to reproduce that character on this keyboard (remember the default keyboard layout is English).
What I'd really like to do is sync the keyboard layouts of the service and the current foreground application, so the service can reproduce any character the user can with their keyboard. GetKeyboardLayout
only works in the current process. This has to run on both 32- and 64-bit, so a message hook is... not preferred :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要检索前台窗口的键盘布局:
听起来您正在录制字符而不是击键。 您可以使用 SendMessage 发送带有记录字符的 WM_CHAR 消息而不是生成击键,而不是在重放时发送击键吗?
To retrieve the keyboard layout for the foreground window:
It sounds like you're recording characters instead of keystrokes. Instead of sending keystrokes when replaying, can you use SendMessage to send WM_CHAR messages with the recorded characters instead of generating keystrokes?