How to clear sticky OneShot modifiers and layers?

Hello,

I would like to have a key that executes a ‘controlled reset’, i.e. it should clear any active modifier (OneShot awaiting timeout or sticky) and turn off any higher layer, activating the first layer (qwerty or equivalent).
This because the keyboard is mounted under the table and I cannot see the LEDs of the modifier keys…

I first thought that it would be good if Escape-OneShot removed the sticky modifiers, but it is probably not good in every case to send Esc to the active application only to reset the keyboard to a defined state.

Thus I bound a macro to an unused key

case MACRO_TO_L0:
Layer.off(L3);
Layer.off(L4);
Layer.off(FUNCTION);
Layer.off(NUMPAD);
break;

The macro seems to clear active modifiers (those awaiting timeout) and to put the keyboard into the first layer.
Unfortunately sticky modifiers are unaffected (neither OSM, nor OSL).
What is missing here?

regards, jo

Escape-OneShot only sends an Escape if there were any oneshots active. Though if you don’t see LEDs, that probably doesn’t help much.

OneShot.cancel(true) :wink:

Put that in the macro, guarded by an if (keyToggledOn(keyState)), and you should be good to go.

Very good, thank you!
The ‘emergency brake’ works as intended now.

regards, jo

I found out that a sticky OSL is not cancelled by the macro if the modifier key itself was not the last key pressed immediately before my macro key.
(e.g.: double tap the modifier that locks the layer for cursor movement, move cursor, tap macro key to cancel stickies → does not work)

Injecting an additional modifier tap before actually cancelling all sticky modifiers worked for me (though probably not a very elegant way…)

OneShot.inject(OSM(LeftShift), keyState);
if (keyToggledOn(keyState)) {
OneShot.cancel(true);
}

regards, jo

Ow, that’s not how it should behave. Can you please open a GitHub issue about this?

Thank you!