Find out when keyboard layout is changed

前端 未结 2 1002
别那么骄傲
别那么骄傲 2021-01-02 02:33

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

Currently I call:

GetKeyboardLayout(GetWi         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 03:10

    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)

提交回复
热议问题