LeftGui in another layout

I have two main layers: PRIMARY, and FUNCTION. Sine I rarely use LeftGui, it is in FUNCTION. That it, to press LeftGui, I have to hold the switch key, and press some other key. The problem is, my FUNCTION layout overrides most keys of my keyboard, so if I try to press LeftGui+E, for instance, it will actually press LeftGui+(E in FUNCTION layout).

I managed to fix this by instead having a macro that 1. deactivates the FUNCTION layer, and 2. sends a raw LeftGui key press, but unfortunately I hit another problem: LeftGui is immediately released.

Here’s the code of the macro (with M(MACRO_TO_GUI) in the FUNCTION layer):

  case MACRO_TO_GUI:
    if (keyToggledOn(keyState)) {
      Layer.deactivate(FUNCTION);
      kaleidoscope::hid::pressRawKey(Key_LeftGui);
      kaleidoscope::hid::sendKeyboardReport();

      return MACRO_NONE;
    } else if (keyToggledOff(keyState)) {
      Layer.activate(FUNCTION);
      kaleidoscope::hid::releaseRawKey(Key_LeftGui);
      kaleidoscope::hid::sendKeyboardReport();

      return MACRO_NONE;
    }
    break;

Any idea how to achieve this?

For a number of technical reasons, Kaleidoscope clears the report every cycle, so if you want a key to be held, you need to “press” it every cycle. The easiest way I can think of right now is to set a flag in the macro on keyToggledOn, and in your loop(), if the flag is set, do a kaleidoscope::hid::pressRawKey(Key_LeftGui), before Kaleidoscope.loop(). Then, in the keyToggledOff branch of the macro, flip the flag off.

1 Like

Ah, thank you for the insight! I expected that Windows required explicit keydown / keyup events, and that not sending anything wouldn’t trigger the keyup. In the end, I just added a new branch

else if (keyIsPressed(keyState)) {
    kaleidoscope::hid::pressRawKey(Key_LeftGui);
    kaleidoscope::hid::sendKeyboardReport();
}

to my macro, so I didn’t even need a global flag! :slight_smile: