[Bf-blender-cvs] [8c878ddd347] master: Fix OS-key events repeating on GHOST/Win32

Campbell Barton noreply at git.blender.org
Sun Sep 18 03:17:41 CEST 2022


Commit: 8c878ddd347c33eee663e7eb48474e59e0997f10
Author: Campbell Barton
Date:   Sun Sep 18 11:02:34 2022 +1000
Branches: master
https://developer.blender.org/rB8c878ddd347c33eee663e7eb48474e59e0997f10

Fix OS-key events repeating on GHOST/Win32

Holding the OS (Windows) key on Win32 used key-repeat behavior.
While as far as I know it didn't cause user visible errors - sending
repeated modifier events isn't expected behavior and doesn't happen
on other platforms (or for other modifier keys).

===================================================================

M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_SystemWin32.cpp

===================================================================

diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 909417e0f50..b3799c53a8d 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -321,6 +321,7 @@ typedef enum {
   GHOST_kKeyBackslash = 0x5C,
   GHOST_kKeyAccentGrave = '`',
 
+  /* Modifiers: See #GHOST_KEY_IS_MODIFIER. */
   GHOST_kKeyLeftShift = 0x100,
   GHOST_kKeyRightShift,
   GHOST_kKeyLeftControl,
@@ -329,6 +330,8 @@ typedef enum {
   GHOST_kKeyRightAlt,
   GHOST_kKeyLeftOS, /* Command key on Apple, Windows key(s) on Windows. */
   GHOST_kKeyRightOS,
+  /* End modifiers. */
+
   GHOST_kKeyGrLess, /* German PC only! */
   GHOST_kKeyApp,    /* Also known as menu key. */
 
@@ -402,6 +405,8 @@ typedef enum {
   GHOST_kKeyMediaLast
 } GHOST_TKey;
 
+#define GHOST_KEY_IS_MODIFIER(key) (key >= GHOST_kKeyLeftShift && key <= GHOST_kKeyRightOS);
+
 typedef enum {
   /** Grab not set. */
   GHOST_kGrabDisable = 0,
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index ce622aa0751..5a40feb70ae 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1136,12 +1136,18 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
   GHOST_TKey key = system->hardKey(raw, &key_down);
   GHOST_EventKey *event;
 
+  /* NOTE(@campbellbarton): key repeat in WIN32 also applies to modifier-keys.
+   * Check for this case and filter out modifier-repeat.
+   * Typically keyboard events are *not* filtered as part of GHOST's event handling.
+   * As other GHOST back-ends don't have the behavior, it's simplest not to send them through.
+   * Ideally it would be possible to check the key-map for keys that repeat but this doesn't look
+   * to be supported. */
   bool is_repeat = false;
   bool is_repeated_modifier = false;
   if (key_down) {
     if (system->m_keycode_last_repeat_key == vk) {
       is_repeat = true;
-      is_repeated_modifier = (key >= GHOST_kKeyLeftShift && key <= GHOST_kKeyRightAlt);
+      is_repeated_modifier = GHOST_KEY_IS_MODIFIER(key);
     }
     system->m_keycode_last_repeat_key = vk;
   }



More information about the Bf-blender-cvs mailing list