Help to figure out easy macro...?

The () on tap and {} on shift-tap is reasonably easy to do with a macro. If you want it to do something on double-tap, the Macros plugin is not enough then, at least, not easily. That’s where TapDance comes into play.

Without the double-tap, this is roughly how it would look:

const macro_t *macroParens(bool left) {
  if (kaleidoscope::hid::wasModifierKeyActive(Key_LeftShift) || 
      kaleidoscope::hid::wasModifierKeyActive(Key_RightShift)) {
    if (left) {
      return MACRO(T(LeftBracket));
    } else {
      return MACRO(T(RightBracket));
    }
  } else {
    if (left) {
      return MACRO(D(LeftShift), T(9), U(LeftShift));
    } else {
      return MACRO(D(LeftShift), T(0), U(LeftShift));
    }
  }
}

And you can call it from macroActions like this:

case M_LPAREN:
    if (keyToggledOn(keyState))
      return macroParens(true);
    break;
case M_RPAREN:
  if (keyToggledOn(keyState))
    return macroParens(false);
  break;

With TapDance, it would look similar, except it has to handle the double-tap case too. I’ll post an update with some code later today to show you how that’s done too.

1 Like