Find out when keyboard layout is changed(找出何时更改键盘布局)
问题描述
我正在编写一个屏幕键盘,并希望在键盘布局更改后立即重新绘制我的布局.
I am writing an onscreen keyboard and would like to redraw my layout as soon as keyboard layout is changed.
目前我打电话:
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.
推荐答案
有办法...
首先您需要注册您的应用程序以捕获前台窗口更改:
使用 SetWinEventHook
和 EVENT_SYSTEM_FOREGROUND
(和 WINEVENT_OUTOFCONTEXT
,因为它是 .NET).
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.
如果发生这种情况:使用您的 GetKeyboardLayout
解决方案获取该窗口的当前布局.
If that happens: Use your GetKeyboardLayout
solution for getting the current layout of that window.
然后使用本地 Windows Hook (您可能在低级别全局使用它来捕获密钥) 与 WH_CALLWNDPROC
和新前台窗口的线程.
收听 WM_INPUTLANGCHANGE
消息接收布局更改的窗口.
(您可能希望在另一个前台更改后取消挂钩/重新挂钩)
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)
这篇关于找出何时更改键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找出何时更改键盘布局
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01