Mapping a single keypress to a chord

I want to program the Any key to send a specific chord: Shift+Alt+Minus. I’ve found the relevant function in the firmware, and I see how to trigger a single key with kaleidoscope::hid::pressKey, but I’m not sure how to send multiple at once. How might I do this?

2 Likes

I think a macro would work; something like the following (warning: untested)

EDIT: I don’t know why I read “shift” as “control” :stuck_out_tongue:

enum macros {
 // this could be whatever you want, just calling it SAM for Shift-Alt-Minus
  MACRO_SAM,
};

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  if (macroIndex == MACRO_SAM) {
    return MACRODOWN(D(LeftShift), D(LeftAlt), T(Minus), U(LeftAlt), U(LeftShift));
  }
 return MACRO_NONE;
}

// Then put M(MACRO_SAM) in your keymap at the appropriate place

3 Likes

That did it, thanks. (I had to replace Control with Shift, but otherwise everything went swimmingly.)

1 Like

Oh good! I updated the snippet there so if anyone else stumbles across it they won’t be confused (no idea how I misread shift as control)

1 Like

Another option is LSHIFT(LALT(Key_Minus)) right in the keymap, or #define KEY_SAM LSHIFT(LALT(Key_Minus)), and use KEY_SAM in the keymap.

This is a slightly underdocumented feature, but you can have keys on the keymap that have LSHIFT, LALT, RALT, LCTRL, LGUI, or any combination of these applied to their normal code. Mind you, this can only be done for keys defined in key_defs_keyboard.h.

7 Likes

Thanks. Though I know it won’t make any difference in the end, is one method faster than the other?

LSHIFT(LALT(Key_Minus)) is a tiny bit faster. My educated guess would be that we’re talking sub-millisecond differences though.

1 Like

That’s about what I figured. Thanks.

Heh, I’m looking to do “hyper” as my own modifier (shift, ctrl, alt, command - I map this non-conflicting custom super-modifier for my own OS mappings). I took a shot at it, but it’s not compiliing:

LSHIFT(LALT(LGUI(LCTRL())))

I must be close, but need a hint!

I _think: LSHIFT(LALT(LGUI(Key_LeftControl))) or something close to that (I haven’t tested that for compilation.)

All of those LBLAH() things are C preprocessor macros that modify the thing inside them. But you’ve got nothing inside to modify.

https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs.h#L78 should help explain it if you have a little bit of C experience.

4 Likes

That did it! Many thanks.

2 Likes

Sorry for resurrecting an old thread, but I’m having a problem here I can’t resolve.
I’m trying to create a new keymap for photoshop shortcuts, so lots of chords involved.

For zooming in with the mouse I need LGUI(Key_Spacebar), but the mac looks at which key was pressed first - if (with QWERTY keymap) I press space and then cmd I get the zoom option in photoshop that I expect. But if I press cmd then space it activates siri.

So unfortunately, just putting LGUI(Key_Spacebar) in the keymap is activating siri (of course!).

I’ve also tried creating a macro that uses keyPress() to send the two individual keys, but that has the same effect.

Any suggestions?

Did you use sendReport() between the key presses? Without that, they’ll be sent in the same batch, and macOS won’t be able to figure out which was pressed first.

1 Like