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

**URL:** <https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177>\
**Category:** Help and Getting Started\
**Created:** [January 19, 2022, 8:27pm UTC](https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177 "2022-01-19T20:27:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gety9](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/gety9/32/4079_2.png) [@gety9](https://community.keyboard.io/u/gety9)\
**Post date:** [January 19, 2022, 8:27pm UTC](https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177/1 "2022-01-19T20:27:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rom1deTroyes](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/rom1detroyes/32/3352_2.png) [@Rom1deTroyes](https://community.keyboard.io/u/Rom1deTroyes)\
**Post date:** [January 22, 2022, 9:02am UTC](https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177/2 "2022-01-22T09:02:47Z")

</div>

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

- 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 🙂

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 🛠

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [January 25, 2022, 5:38am UTC](https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177/3 "2022-01-25T05:38:35Z")

</div>

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](https://kaleidoscope.readthedocs.io/en/latest/customization/plugin-authors-guide.html).

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [February 6, 2022, 8:31pm UTC](https://community.keyboard.io/t/can-i-modify-ctrl-behavior-when-its-pressed-with-j-l-using-chrysalis/5177/4 "2022-02-06T20:31:24Z")

</div>

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

```auto
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.
