From d5e2f5e59653547e63a2e333919b5132b8e82a2c Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 28 Jan 2003 23:37:49 +0000 Subject: [PATCH] filter bad WM_SETFOCUS message --- panda/src/windisplay/winGraphicsWindow.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index 811bd876b3..8277e90215 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -945,6 +945,19 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // when focus is regained, compare the state of the keyboard to // the last known state (stored above, when focus was lost) to // regenerate the lost keyboard events. + + if (GetForegroundWindow() != _mwindow) { + // Sometimes, particularly on window create, it appears we get + // a WM_SETFOCUS event even though the window hasn't really + // received focus yet. That's bad and confuses the + // GetKeyboardState logic, below. The above check filters out + // this case (while testing GetFocus() instead of + // GetForegroundWindow() doesn't). + windisplay_cat.debug() + << "Got incorrect WM_SETFOCUS\n"; + break; + } + BYTE new_keyboard_state[num_virtual_keys]; GetKeyboardState(new_keyboard_state); for (int i = 0; i < num_virtual_keys; i++) {