I want my Ctrl (or Alt, …) key to act like a function key when I chord certain key combinations.
Let’s say I want my Ctrl key combos to behave normally except when I chord Ctrl+c. When I press Ctrl+c, I want the keyboard to send an “up” keycode instead of the usual Ctrl+c.
What I don’t want to do is make Ctrl a layer key, make everything send LCTRL(key) on that leyer, but for Ctrl+c it would send Key_UpArrow instead.
Is there a way to accomplish that without making Ctrl a function key? It would be an awful lot of work and a waste of precious memory if I had to do that for every modifier key. There are only a few key combinations I want to alter, which is why introducing a new layer would be such a waste.
The easiest, in my opinion, would be a custom event handler hook, something along these lines:
Key customControls(Key mapped_key, byte row, byte col, uint8_t key_state) {
// If none of the controls are pressed, fall through.
if (!kaleidoscope::hid::wasModifierKeyActive(Key_LeftControl) &&
!kaleidoscope::hid::wasModifierKeyActive(Key_RightControl) {
return mapped_key;
// Either left or right control is active!
// If the key isn't C, fall through
if (mapped_key != Key_C)
return mapped_key;
// If we are idle, fall through
if (!keyWasPressed(key_state) && !keyIsPressed(key_state))
return mapped_key;
// So we are not idle, one of the controls are held, and C is our key.
// Time to release the Kraken^WControls, and replace C with UpArrow.
kaleidoscope::hid::releaseKey(Key_LeftControl);
kaleidoscope::hid::releaseKey(Key_RightControl);
return Key_UpArrow;
}
// Somewhere in `setup()`:
Kaleidoscope.useEventHandlerHook(customControls);
This is all untested code, mind you, and may or may not work, or have side effects. It may not even be the best solution. But this is the first that came to mind.
Yup! LCTRL(Key_C). There is also LALT, RALT, LSHIFT, and LGUI and they can be combined, so you could write return LSHIFT(LCTRL(Key_C)) to send Control-Shift-C.