How to obtain keyboard layout for Microsoft Edge and other windows hosted in ApplicationFrameHost.exe
问题 As we all know, Windows's keyboard layouts are thread-specific. When a layout changes, a message is dispatched to the foreground thread by the shell. So if one wants to obtain the most recent system-wide keyboard layout, one must do something like this: const HWND foregroundWindow = ::GetForegroundWindow(); const DWORD foregroundThread = ::GetWindowThreadProcessId(foregroundWindow, NULL); const HKL layout = ::GetKeyboardLayout(foregroundThread); This works fine for most native Windows apps.