了解键盘布局何时更改

发布于 2024-12-18 02:13:21 字数 274 浏览 1 评论 0原文

我正在编写一个屏幕键盘,并且希望在键盘布局更改后立即重新绘制布局。

目前,我

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 技术交流群。

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

发布评论

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

评论(2

爱冒险 2024-12-25 02:13:21

有一种方法...

首先,您需要注册您的应用程序以捕获前景窗口的变化:
SetWinEventHookEVENT_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 with EVENT_SYSTEM_FOREGROUND (and WINEVENT_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)

清醇 2024-12-25 02:13:21

看起来键盘布局存储在这里:
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

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