MACRODOWN is deprecated, what's the alternative?

I have updated to the latest Kalaidoscope firmware for my Model01 and after porting a few obvious things I got stuck at compiler error for MACRODOWN

Model01-Firmware.ino: In function 'const macro_t* macroAction(uint8_t, uint8_t)':
.arduino15/packages/keyboardio/hardware/avr/2022.1.16192526/libraries/Kaleidoscope-Macros/src/kaleidoscope/plugin/Macros/MacroSteps.h:57:23: error: 'event' was not declared in this scope
   deprecatedMacroDown(event.state, MACRO(__VA_ARGS__));
                       ^
Model01-Firmware.ino:605:12: note: in expansion of macro 'MACRODOWN'
     return MACRODOWN(D(RightControl), T(C), T(C), U(RightControl));
            ^~~~~~~~~

MACRODOWN calls a function or another macro now named deprecatedMacroDown, which does not seem to work. Either way I would like to update my code to the way it’s supposed to be done now with the latest version.

My macroAction function contains a lot of switch case statements such as

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  switch (macroIndex) {
  //...
  case MACRO_ORG_CLOCK_IN:
    return MACRODOWN(D(LeftControl), D(LeftShift), D(LeftAlt), T(F7), U(LeftAlt), U(LeftControl), U(LeftShift));        
  //...
}

What is the alternative to MACRODOWN?

The Kalaidoscope version I’m using is 2022.1.16192526.

First, you should replace your macroAction(uint8_t macroIndex, uint8_t keyState) function with the newer macroAction(uint8_t macro_id, KeyEvent &event). Then, instead of using return MACRODOWN(...), first use an if (keyToggledOn(event.state)) {...} somewhere, and return MACRO(...).

MACRODOWN() was deprecated because it is much less essential now that macroAction() only gets called when a key toggles on or off, not every cycle.

Furthermore, in the one example above, you don’t even need to use Macros at all. A key defined as LCTRL(LSHIFT(LALT(Key_F7))) is simpler, and arguably superior.

2 Likes

I see now that the Macros plugin has its own separate UPGRADING document, which doesn’t show up on kaleidoscope.readthedocs.io. It also doesn’t include a section on replacing the deprecated MACRODOWN(). Both of these are oversights on my part. I’ll try to rectify those problems soon.

3 Likes

That worked out well, thank you!

Furthermore, in the one example above, you don’t even need to use Macros at all. A key defined as LCTRL(LSHIFT(LALT(Key_F7))) is simpler, and arguably superior.

I have replaced my macro with that, but other macros cannot be replaced, eg. MACRODOWN(D(RightControl), T(C), T(C), U(RightControl)). I have been wondering why there aren’t any RCTRL, RSHIFT and RGUI macros, only RALT. (despite there being Key_RightGui, Key_RightControl, …)

(I’m referring to this source Kaleidoscope/keycodes.md at ea45b7807164c18b0df28c74c045672d12b50f18 · keyboardio/Kaleidoscope · GitHub)

Each one of those macros sets one bit in the “flags” byte of the 16-bit Key structure. If we used all eight bits in that byte for modifier flags, Kaleidoscope would need to use at least three bytes to store Key values instead of two, which would increase the size of the keymap, and reduce the number of layers that could be stored. Since the only modifier for which a distinction is commonly made is alt (right alt = AltGr), that’s the only one that gets both.

2 Likes