MACROSDOWN in MagicCombo not working

Hello. I’m trying to set up hitting the two Fn keys together to put my system to sleep as I didn’t want to put the System_Sleep key on a keymap for fear of accidentally pressing it (to avoid the hassle of waking it up again and entering the password). As per the example given in the MagicCombo plugin, my code is:

void magicSleep(uint8_t combo_index)

  .action = magicSleep,
  .keys = {R3C6, R3C9} // Left Fn + Right Fn

but upon doing make flash I’m getting the following errors:

BOARD_HARDWARE_PATH="/home/samjnaa/Arduino/hardware" /home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/bin//kaleidoscope-builder flash
Building output/Model01-Firmware/Model01-Firmware (0.0.0-gv1.22-15-g173c-dirty) ...
In file included from /home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/src/key_events.h:6:0,
                 from /home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/src/Kaleidoscope.h:24,
                 from /home/samjnaa/Arduino/Model01-Firmware/Model01-Firmware.ino:6:
/home/samjnaa/Arduino/Model01-Firmware/Model01-Firmware.ino: In function 'void magicSleep(uint8_t)':
/home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope-Macros/src/MacroSteps.h:22:38: error: 'keyState' was not declared in this scope
 #define MACRODOWN(...) (keyToggledOn(keyState) ? MACRO(__VA_ARGS__) : MACRO_NONE)
/home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope/src/keyswitch_state.h:17:35: note: in definition of macro 'keyIsPressed'
 #define keyIsPressed(keyState)  ((keyState) & IS_PRESSED)
/home/samjnaa/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope-Macros/src/MacroSteps.h:22:25: note: in expansion of macro 'keyToggledOn'
 #define MACRODOWN(...) (keyToggledOn(keyState) ? MACRO(__VA_ARGS__) : MACRO_NONE)
/home/samjnaa/Arduino/Model01-Firmware/Model01-Firmware.ino:153:5: note: in expansion of macro 'MACRODOWN'
/home/samjnaa/Arduino/Model01-Firmware/Model01-Firmware.ino: At global scope:
/home/samjnaa/Arduino/Model01-Firmware/Model01-Firmware.ino:156:17: error: expected constructor, destructor, or type conversion before '(' token
exit status 1
/home/samjnaa/Arduino/hardware/keyboardio/avr/build-tools/makefiles// recipe for target 'flash' failed
make: *** [flash] Error 1

It looks like it is looking for a parameter keyState but which is not defined by the combo handler (as per the example). Kindly advise as to how this is to be fixed. Thank you!

MACRODOWN is a helper that only really works from macroActions, and is expected that its return value is returned directly. That’s what it was designed for. It expands to this:

(keyToggledOn(keyState) ? MACRO(...) : MACRO_NONE)

As magicSleep does not return anything, let alone a macro, even if keyState would be available here, MACRODOWN would do nothing.

MagicCombo does not use keyState in the callback, because the callback is only fired when the combo keys are held (and nothing else is), so it wouldn’t make sense there.

If you want to press keys from a MagicCombo action, you can use

void magicSleep(uint8_t combo_index) {;

Or, if you want to be a tiny bit more efficient, inject the key press directly:

void magicSleep(uint8_t combo_index) {

Hope this helps!

1 Like

Yes this is documented in the README. Sorry for not noticing.

I decided to forgo MagicCombo for now and just mapped System_Sleep to the left Fn key in the layer invoked by the right Fn key. I expect that might be even faster?

Yep, it will be, though you’ll have to keep in mind that you need to press right Fn first. With MagicCombo, the order wouldn’t matter.

1 Like