I\'m writting console app that should indicate keyboard layout. I\'m using GetForegroundWindow() function to get current active window, function GetWindow
Your code is right, It's Microsoft's problem. I run this code in a third-party shell, babun and get the right result. You can try this shell, I think it's the best shell on Windows.