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).
This commit is contained in:
Campbell Barton
2022-09-18 11:02:34 +10:00
parent 0950e6fae6
commit 8c878ddd34
2 changed files with 12 additions and 1 deletions

View File

@@ -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,

View File

@@ -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;
}