Can i modify ctrl behavior when it's pressed with j/l using Chrysalis?

Hello everyone!

Yesterday received Atreus, and i love it so far! Chrysalis is also pretty beginner friendly! Kudos to keyboardio team and community.

I was not able to figure out what’s the best way to achive the following:

I’d like to overwrite/modify ctrl for j and l,
meaning:

ctrl+a=ctrl+a

ctrl+j=ctrl+left arrow
ctrl+l=ctrl+right arrow

ctrl+z=ctrl+z

basically ctrl behaves as usuall except for j and l keys.

An easy way to achieve this could be to have a «control layer» :keyboard:

  • Add a new layer (let’s say layer7)
  • on this layer, put all the letters with the control modifer
  • on the base layer (layer 1) replace the control key by a Shift to layer 7 (your control layer defined above)
  • now you can change j and k by arrows keys, than move the j to an useless symbol because it’s used for snippet navigation, and even move Ctrl-w to avoid closing firefox tabs :slight_smile:

As the process can be long, you can start with a 4 letters layer (z a j k?) to validate the idea, and take the time to finish the layer if it’s ok !

Happy hacking :hammer_and_wrench:

1 Like

You could also use a fairly simple custom plugin for this. It would define an onKeyEvent() handler, which would do nothing unless a Key_J or Key_K toggle on event was received. In that case, it would search the live_keys array for a Key_LeftControl (and/or Key_RightControl, or possibly any modifier key including a control bit), and if one is found, it would change the value of event.key to Key_LeftArrow or Key_RightArrow.

For a guide on how to do stuff like this, check out the Plugin Author’s Guide.

1 Like

Here’s a little plugin that you can add to your sketch to do this:

namespace kaleidoscope {
namespace plugin {

// Plugin that converts `ctrl`+`j` to `ctrl`+`left arrow` and `ctrl`+`l` to
// `ctrl`+`right arrow`.
class CtrlJLArrows : public Plugin {
 public:
  EventHandlerResult onKeyEvent(KeyEvent &event) {
    // We only care about events where `j` or `l` toggles on, so return `OK`
    // immediately in all other cases.
    if (!keyToggledOn(event.state) ||
        (event.key != Key_J && event.key != Key_L))
      return EventHandlerResult::OK;

    // Search `live_keys` for an active `ctrl` key.
    bool ctrl_active = false;
    for (Key key : live_keys.all()) {
      if (key == Key_LeftControl || key == Key_RightControl) {
        ctrl_active = true;
        break;
      }
    }
    // If we found an active `ctrl` key, replace the `j` or `l` with an arrow.
    if (ctrl_active) {
      if (event.key == Key_J) {
        event.key = Key_LeftArrow;
      } else {
        event.key = Key_RightArrow;
      }
    }
    return EventHandlerResult::OK;
  }
};

} // namespace plugin
} // namespace kaleidoscoope

kaleidoscope::plugin::CtrlJLArrows CtrlJLArrows;

KALEIDOSCOPE_INIT_PLUGINS(CtrlJLArrows);

You would also include any other plugins that you’re using in the call to KALEIDOSCOPE_INIT_PLUGINS(), with CtrlJLArrows somewhere near the bottom of the list.

1 Like