Browse Source

filter bad WM_SETFOCUS message

David Rose 23 years ago
parent
commit
d5e2f5e596
1 changed files with 13 additions and 0 deletions
  1. 13 0
      panda/src/windisplay/winGraphicsWindow.cxx

+ 13 - 0
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
       // when focus is regained, compare the state of the keyboard to
       // the last known state (stored above, when focus was lost) to
       // the last known state (stored above, when focus was lost) to
       // regenerate the lost keyboard events.
       // 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];
       BYTE new_keyboard_state[num_virtual_keys];
       GetKeyboardState(new_keyboard_state);
       GetKeyboardState(new_keyboard_state);
       for (int i = 0; i < num_virtual_keys; i++) {
       for (int i = 0; i < num_virtual_keys; i++) {