Browse Source

by default, don't think keys are held down when window focus is lost.

David Rose 22 years ago
parent
commit
3ea371a282

+ 6 - 3
panda/src/windisplay/config_windisplay.cxx

@@ -33,9 +33,12 @@ float fps_meter_update_interval = max(0.5,config_windisplay.GetFloat("fps-meter-
 
 bool responsive_minimized_fullscreen_window = config_windisplay.GetBool("responsive-minimized-fullscreen-window",false);
 
-// Set this true to not attempt to use any of the function calls that
-// will crab out WireGL.
-bool support_wiregl = config_windisplay.GetBool("support-wiregl", false);
+// Set this true to remember the current state of the keyboard while
+// the window focus is lost, or false to pretend the user is not
+// holding down any keys while the window focus is lost.  In either
+// case it should accurately restore the correct keyboard state when
+// the window focus is regained.
+bool hold_keys_across_windows = config_windisplay.GetBool("hold-keys-across-windows", false);
 
 // if true, use ddraw's GetAvailVidMem to fail if driver says it has too little video mem
 bool do_vidmemsize_check = config_windisplay.GetBool("do-vidmemsize-check", true);

+ 1 - 0
panda/src/windisplay/config_windisplay.h

@@ -32,6 +32,7 @@ extern Filename get_mono_cursor_filename();
 extern bool show_fps_meter;
 extern float fps_meter_update_interval;
 extern bool responsive_minimized_fullscreen_window;
+extern bool hold_keys_across_windows;
 extern bool do_vidmemsize_check;
 extern bool ime_composition_w;
 

+ 31 - 18
panda/src/windisplay/winGraphicsWindow.cxx

@@ -994,29 +994,42 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
           windisplay_cat.debug()
             << "killfocus\n";
         }
-        if (_lost_keypresses) {
-          resend_lost_keypresses();
-        }
+        if (!_lost_keypresses) {
+          // Record the current state of the keyboard when the focus is
+          // lost, so we can check it for changes when we regain focus.
+          GetKeyboardState(_keyboard_state);
+          if (windisplay_cat.is_debug()) {
+            // Report the set of keys that are held down at the time of
+            // the killfocus event.
+            for (int i = 0; i < num_virtual_keys; i++) {
+              if (i != VK_SHIFT && i != VK_CONTROL && i != VK_MENU) {
+                if ((_keyboard_state[i] & 0x80) != 0) {
+                  windisplay_cat.debug()
+                    << "on killfocus, key is down: " << i
+                    << " (" << lookup_key(i) << ")\n";
+                }
+              }
+            }
+          }
 
-        // Record the current state of the keyboard when the focus is
-        // lost, so we can check it for changes when we regain focus.
-        GetKeyboardState(_keyboard_state);
-        if (windisplay_cat.is_debug()) {
-          // Report the set of keys that are held down at the time of
-          // the killfocus event.
-          for (int i = 0; i < num_virtual_keys; i++) {
-            if (i != VK_SHIFT && i != VK_CONTROL && i != VK_MENU) {
-              if ((_keyboard_state[i] & 0x80) != 0) {
-                windisplay_cat.debug()
-                  << "on killfocus, key is down: " << i << " (" << lookup_key(i) << ")\n";
+          if (!hold_keys_across_windows) {
+            // If we don't want to remember the keystate while the
+            // window focus is lost, then generate a keyup event
+            // right now for each key currently held.
+            for (int i = 0; i < num_virtual_keys; i++) {
+              if (i != VK_SHIFT && i != VK_CONTROL && i != VK_MENU) {
+                if ((_keyboard_state[i] & 0x80) != 0) {
+                  handle_keyrelease(lookup_key(i));
+                  _keyboard_state[i] &= ~0x80;
+                }
               }
             }
           }
+          
+          // Now set the flag indicating that some keypresses from now
+          // on may be lost.
+          _lost_keypresses = true;
         }
-
-        // Now set the flag indicating that some keypresses from now
-        // on may be lost.
-        _lost_keypresses = true;
         break;
     
       case WM_SETFOCUS: