了解键盘布局何时更改
我正在编写一个屏幕键盘,并且希望在键盘布局更改后立即重新绘制布局。
目前,我
GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL));
在每次按键时调用:以查明布局是否已更改。如果用户通过鼠标更改布局,则在按下按键之前不起作用。
我想知道是否有什么办法可以得到通知 当当前前台窗口的键盘布局改变时, 这样我就可以在更改发生后立即重新绘制布局。
I am writing an onscreen keyboard and would like to redraw my layout as soon as keyboard layout is changed.
Currently I call:
GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL));
on every key press to find out if the layout has changed. It does not work if user changes the layout by mouse, until key is pressed.
I would like to know if there is any way to get notified
when the keyboard layout of the current foreground window is changed,
so I can redraw my layout as soon as the change happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种方法...
首先,您需要注册您的应用程序以捕获前景窗口的变化:
将
SetWinEventHook
与EVENT_SYSTEM_FOREGROUND
结合使用 (以及WINEVENT_OUTOFCONTEXT
,因为它是.NET)。如果发生这种情况:使用
GetKeyboardLayout
解决方案获取该窗口的当前布局。然后使用本地 Windows Hook (你可能在全局范围内使用它来进行关键捕获) 和
WH_CALLWNDPROC
和新前台窗口的线程。监听
WM_INPUTLANGCHANGE
消息用于接收布局更改的窗口。(您可能想在另一次前台更改后取消挂钩/重新挂钩)
There is a way ...
First you need to register your application to capture foreground window changes:
Use
SetWinEventHook
withEVENT_SYSTEM_FOREGROUND
(andWINEVENT_OUTOFCONTEXT
as it's .NET) for that.If that happens: Use your
GetKeyboardLayout
solution for getting the current layout of that window.Then use a local Windows Hook (you're probably using it low-level-globally for key captures) with
WH_CALLWNDPROC
and the thread of the new foreground window.Listen to
WM_INPUTLANGCHANGE
messages to that window to receive changes to the layout.(You may want to unhook/rehook after another foreground change)
看起来键盘布局存储在这里:
HKEY_CURRENT_USER\Keyboard Layout\Preload
当我更改键盘语言时,那里的设置顺序发生了变化。
因此您可以监视注册表项。这是一种方法:
http://www.codeproject.com/KB/system/registrymonitor.aspx
It looks like the keyboard layout is stored here:
HKEY_CURRENT_USER\Keyboard Layout\Preload
When I changed keyboard languages, the order of settings there changed.
So you could possibly monitor the registry entry. Here's one way:
http://www.codeproject.com/KB/system/registrymonitor.aspx