Brackets as pseudo-modifier

I’m interested in having keys (for (), {}, [] and <>) which do the open version on keypress and the closed version on release, so that on typing as you hold it, anything typed in between is enclosed, as if it were a kind of modifier. Anyone tried anything along these lines?

So to be completely clear, HoldButton I want this to be in parentheses ReleaseButton should result in (I want this to be in parentheses)

3 Likes
#define Key_Brackets Key(kaleidoscope::ranges::SAFE_START)

EventHandlerResult 
onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
  if (mapped_key != Key_Brackets)
    return EventHandlerResult::OK;

  if (keyToggledOn(key_state)) {
    mapped_key = LSHIFT(Key_9);
  } else if (keyToggledOff(key_state)) {
    mapped_key = LSHIFT(Key_0);
  } else {
    return EventHandlerResult::EVENT_CONSUMED;
  }

  return EventHandlerResult::OK;
}

Something along these lines, as a starting point? Wrap it in plugin boilerplate, spice it up with support for the other brackets, and you should be good to go.

Mind you, it’s completely untested code, and it’s 3am, so I take no responsibility if it starts mining bitcoin by accident.

4 Likes

Well I was going to give you a cut of the farmed bitcoin, but now I can skip that with a clear conscience!

I might give that a shot tonight, thanks!

2 Likes

While I haven’t had time to do this anyway, I do plan to do a much simpler macro in addition, probably on a different layer by same position as the keys which are being referenced, which puts (),{},[] or <> around highlighted text (i.e. ctrl-x,openThing,ctrl-v,closeThing, with some sensible delay). Happy to share the code but I imagine almost everyone here can figure this out themselves.

2 Likes