Help to figure out easy macro...?


(David Fudge) #1

hi everyone- i’m finally getting pretty good with my model 01 but i have an optimization i’d love to make but can’t figure out how to create a macro for it.

what i want to do is have my butterfly key insert () when i tap it, or {} when i tap it with SHIFT or ({}) if i double-tap it. is that possible?

i’ve looked at the docs for the macro plugin, but it’s kind of confusing, and i looked at the firmware macros that already exist and those are also confusing. any help here is appreciated.


(Gergely Nagy) #2

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.


(Ben Gemperline) #3

You might also want to take a look at SpaceCadet if you want more granular control over the individual taps. For example, I’ve got ( mapped to left shift, { mapped to left cmd, and [ mapped to right control (with the complements mapped on the right hand).