I'm writting console app that should indicate keyboard layout. I'm using GetForegroundWindow()
function to get current active window, function GetWindowThreadProcessId()
to get thread id, and finally, with function GetKeyboardLayout()
I get keyboard layout. Everyting works fine with any application I try except some cases:
- When I switch window to cmd.exe or any other console app it shows default layout, changing layout have no effect
- In games is the same situation
- All threads of the same process have the same layout [tested on explorer.exe (this confused me as I think layout is thread specified)
Please, explain me what is going on. Below is my test code
#include <Windows.h>
#include <iostream>
int main()
{
while(8)
{
HWND _curr_window = GetForegroundWindow();
DWORD _curr_window_procces_id;
DWORD _curr_window_thread_id = GetWindowThreadProcessId(_curr_window, &_curr_window_procces_id);
std::cout << "Process ID is " << _curr_window_procces_id << " and Thread ID is " << _curr_window_thread_id << std::endl;
HKL _key_locale = GetKeyboardLayout(_curr_window_thread_id);
std::cout << "Keyboard layout is " << _key_locale << std::endl;
Sleep(1000);
}
return 0;
}