找出当键盘布局发生变化 [英] Find out when keyboard layout is changed

查看:178
本文介绍了找出当键盘布局发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的屏幕键盘,并想尽快的键盘布局改变重绘我的布局。

I am writing an onscreen keyboard and would like to redraw my layout as soon as keyboard layout is changed.

目前我呼吁:

GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL));

在每一个关键的preSS,以找出是否布局发生了变化。如果用户更改鼠标的布局实在不行,直到关键是pressed。

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.

推荐答案

有一种方法...

There is a way ...

首先,您需要注册您的应用程序捕获前台窗口的变化:
使用<一个href="http://msdn.microsoft.com/library/windows/desktop/dd373640.aspx"><$c$c>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挂钩 (你可能会使用它的低级别,全球范围内为重点捕获)的与 WH_CALLWNDPROC 和新的前台窗口的线程。
听<一个href="http://msdn.microsoft.com/library/windows/desktop/ms632629.aspx"><$c$c>WM_INPUTLANGCHANGE消息该窗口接收更改布局。
(您可能需要另一种前景更改后解开/ rehook)

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)

这篇关于找出当键盘布局发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆