How is it possible to know the current keyboard layout of a console window having the window handle provided?
For a GUI window it is possible via:
const auto threadId = ::GetWindowThreadProcessId(hwnd, nullptr);
const auto hkl = ::GetKeyboardLayout(idThread);
But this approach doesn't work for console windows.
After some google'ing I ended up with the following results:
Since Win7 the keyboard layout for console application can be received from
conhost.exe
process, which is a child process ofcmd.exe
. A little more details can be found here:
https://autohotkey.com/board/topic/43043-get-current-keyboard-layout/But in this question:
c++ how do i get the current console conhost process I found the comment from @RaymondChen thatconhost.exe
- is an implementation detail, which might not exist in some Windows versions.
So, non-standard workaround seems to be possible. But is there any standard, compatible way to get the right result?
PS, similar question is asked here:
GetKeyboardLayout() doesn't work properly in some cases
But it has no answer on my question.