diff --git a/src/modules/keyboardmanager/common/Shortcut.cpp b/src/modules/keyboardmanager/common/Shortcut.cpp index b836786a77..8ebed5f337 100644 --- a/src/modules/keyboardmanager/common/Shortcut.cpp +++ b/src/modules/keyboardmanager/common/Shortcut.cpp @@ -613,25 +613,53 @@ bool Shortcut::CheckModifiersKeyboardState(InputInterface& ii) const return true; } +// Helper method for checking if a key is in a range for cleaner code +bool in_range(DWORD key, DWORD a, DWORD b) +{ + return (key >= a && key <= b); +} + +// Helper method for checking if a key is equal to a value for cleaner code +bool equals(DWORD key, DWORD a) +{ + return (key == a); +} + // Function to check if the key code is to be ignored bool IgnoreKeyCode(DWORD key) { + // Ignore mouse buttons. Keeping this could cause a remapping to fail if a mouse button is also pressed at the same time switch (key) { - // Ignore mouse buttons. Keeping this could cause a remapping to fail if a mouse button is also pressed at the same time case VK_LBUTTON: case VK_RBUTTON: case VK_MBUTTON: case VK_XBUTTON1: case VK_XBUTTON2: - // Ignore these key codes as they are reserved. Used by IME keyboards. More information at https://github.com/microsoft/PowerToys/issues/5225 - case 0xF0: - case 0xF1: - case 0xF2: return true; } - return false; + // As per docs: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes + // Undefined keys + bool isUndefined = equals(key, 0x07) || in_range(key, 0x0E, 0x0F) || in_range(key, 0x3A, 0x40); + + // Reserved keys + bool isReserved = in_range(key, 0x0A, 0x0B) || equals(key, 0x5E) || in_range(key, 0xB8, 0xB9) || in_range(key, 0xC1, 0xD7) || equals(key, 0xE0) || equals(key, VK_NONAME); + + // Unassigned keys + bool isUnassigned = in_range(key, 0x88, 0x8F) || in_range(key, 0x97, 0x9F) || in_range(key, 0xD8, 0xDA) || equals(key, 0xE8); + + //OEM Specific keys. Ignore these key codes as some of them are used by IME keyboards. More information at https://github.com/microsoft/PowerToys/issues/5225 + bool isOEMSpecific = in_range(key, 0x92, 0x96) || equals(key, 0xE1) || in_range(key, 0xE3, 0xE4) || equals(key, 0xE6) || in_range(key, 0xE9, 0xF5); + + if (isUndefined || isReserved || isUnassigned || isOEMSpecific) + { + return true; + } + else + { + return false; + } } // Function to check if any keys are pressed down except those in the shortcut