From 588f25753063734459ffbe0eaea528f9da0b3467 Mon Sep 17 00:00:00 2001 From: "syed.amer@gilani.eu" Date: Thu, 25 Feb 2010 14:21:47 +0000 Subject: [PATCH] check the return value of GetKeyboardLayout for 0 and take the keyboard layout of the desktop HWND instead Issue #386 --- lib/platform/CMSWindowsKeyState.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/platform/CMSWindowsKeyState.cpp b/lib/platform/CMSWindowsKeyState.cpp index 0e9daf8a..788e9d5a 100644 --- a/lib/platform/CMSWindowsKeyState.cpp +++ b/lib/platform/CMSWindowsKeyState.cpp @@ -854,6 +854,14 @@ CMSWindowsKeyState::pollActiveGroup() const // get keyboard layout for the thread HKL hkl = GetKeyboardLayout(targetThread); + if (!hkl) { + // GetKeyboardLayout failed. Maybe targetWindow is a console window. + // We're getting the keyboard layout of the desktop instead. + targetWindow = GetDesktopWindow(); + targetThread = GetWindowThreadProcessId(targetWindow, NULL); + hkl = GetKeyboardLayout(targetThread); + } + // get group GroupMap::const_iterator i = m_groupMap.find(hkl); if (i == m_groupMap.end()) {