diff --git a/src/Kaleidoscope-Ranges.h b/src/Kaleidoscope-Ranges.h index d0135173..dfa4a62b 100644 --- a/src/Kaleidoscope-Ranges.h +++ b/src/Kaleidoscope-Ranges.h @@ -49,6 +49,8 @@ enum : uint16_t { SC_LAST, REDIAL, TURBO, + MACRO_FIRST, + MACRO_LAST = MACRO_FIRST + 255, DYNAMIC_MACRO_FIRST, DYNAMIC_MACRO_LAST = DYNAMIC_MACRO_FIRST + 31, diff --git a/src/kaleidoscope/plugin/Macros.cpp b/src/kaleidoscope/plugin/Macros.cpp index 3b7c0a9f..eb83f648 100644 --- a/src/kaleidoscope/plugin/Macros.cpp +++ b/src/kaleidoscope/plugin/Macros.cpp @@ -244,7 +244,7 @@ const macro_t *Macros_::type(const char *string) { } bool Macros_::isMacroKey(Key key) { - if (key.getFlags() == (SYNTHETIC | IS_MACRO)) + if (key >= ranges::MACRO_FIRST && key <= ranges::MACRO_LAST) return true; return false; } @@ -253,7 +253,8 @@ EventHandlerResult Macros_::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, u if (! isMacroKey(mappedKey)) return EventHandlerResult::OK; - addActiveMacroKey(mappedKey.getKeyCode(), key_addr.toInt(), keyState); + uint8_t macro_index = mappedKey.getRaw() - ranges::MACRO_FIRST; + addActiveMacroKey(macro_index, key_addr.toInt(), keyState); return EventHandlerResult::EVENT_CONSUMED; } diff --git a/src/kaleidoscope/plugin/Macros/MacroKeyDefs.h b/src/kaleidoscope/plugin/Macros/MacroKeyDefs.h index a12cd038..ede4ce7a 100644 --- a/src/kaleidoscope/plugin/Macros/MacroKeyDefs.h +++ b/src/kaleidoscope/plugin/Macros/MacroKeyDefs.h @@ -16,9 +16,12 @@ #pragma once -#define IS_MACRO B00100000 +#include "Kaleidoscope-Ranges.h" + +constexpr Key M(uint8_t n) { + return Key(kaleidoscope::ranges::MACRO_FIRST + n); +} -#define M(n) Key(n, KEY_FLAGS | SYNTHETIC | IS_MACRO) #define Key_macroKey1 M(1) #define Key_macroKey2 M(2) #define Key_macroKey3 M(3)