Fix #68256: Win32 Treat AltGr Exactly as Alt Key

Windows Only. On some keyboard layouts, the right Alt key behaves as an
"AltGR" key. This key emits both right alt and left ctrl key events,
which means that it won't match keyboard shortcuts set to just Alt.
This PR, for just layouts that include AltGr, if the scancode is for
right Alt yet the virtual key is actually the control key then ignore
these key events. This treats AltGr exactly as Alt.

Pull Request: https://projects.blender.org/blender/blender/pulls/132536
This commit is contained in:
Harley Acheson
2025-01-06 22:12:40 +01:00
committed by Harley Acheson
parent 72180241c1
commit d99d19cd22

View File

@@ -1258,6 +1258,19 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
GHOST_TKey key = system->hardKey(raw, &key_down);
GHOST_EventKey *event;
/* Scan code (device-dependent identifier for the key on the keyboard) for the Alt key.
* https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#scan-codes */
constexpr USHORT ALTGR_MAKE_CODE = 0x38;
/* If the keyboard layout includes AltGr and the virtual key is Control, yet the
* scancode is actually for Right Alt (ALTGR_MAKE_CODE scan code with E0 prefix).
* Ignore these, so treating AltGR as regular Alt. #68256 */
if (system->m_hasAltGr && vk == VK_CONTROL && raw.data.keyboard.MakeCode == ALTGR_MAKE_CODE &&
(raw.data.keyboard.Flags & RI_KEY_E0))
{
return nullptr;
}
/* NOTE(@ideasman42): 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.