MACRO helper is producing double characters

I am building a sketch for my Atreus and I have run into a problem with the MACRO helper. These are my macros

static void anyKeyMacro(KeyEvent &event) {
if (keyToggledOn(event.state)) {
event.key.setKeyCode(Key_A.getKeyCode() + (uint8_t)(millis() % 36));
event.key.setFlags(0);
}
}

const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) {
switch (macro_id) {

case MACRO_ANY:
anyKeyMacro(event);
break;

case MACRO_VERSION_INFO:
if (keyToggledOn(event.state)) {
Macros.type(PSTR("Keyboardio Atreus - Kaleidoscope "));
Macros.type(PSTR(BUILD_INFORMATION));
}
break;

case caron:
return MACRO(
D(RightAlt), D(LeftShift), T(Period), U(LeftShift), U(RightAlt) );
break;

case egrave:
return MACRO( T(Backtick), T(E) );
break;

case ouml:
return MACRO(
Tr(LSHIFT(Key_Quote)), T(O));
break;

case yuml:
return MACRO(
Tr(LSHIFT(Key_Quote)), T(Y));
break;

default:
Macros.type(PSTR(" UNDEFINED MACRO "));
break;

}
return MACRO_NONE;
}

M(egrave), M(ouml), and M(yuml) produce èè, öö, and ÿÿ. The caron macro is ill as well. I think I vaguely remember having a similar problem in the past, but I don’t remember what I did to fix it.

Those macros are triggering on both key press and release (try pressing and holding one of those keys, then releasing it after a second or two, and I expect you to see only one character when it toggles on, then a second one when it toggles off). To stop that, wrap them in the following:

if (keyToggledOn(event.state)) {
  return MACRO(...);
}
3 Likes