# How to clear sticky OneShot modifiers and layers?

**URL:** <https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703>\
**Category:** Programming\
**Created:** [July 1, 2018, 9:20pm UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703 "2018-07-01T21:20:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cerise](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cerise](https://community.keyboard.io/u/cerise)\
**Post date:** [July 1, 2018, 9:20pm UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703/1 "2018-07-01T21:20:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [July 1, 2018, 9:35pm UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703/2 "2018-07-01T21:35:49Z")

</div>

> [@cerise](#):
>
> 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.

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

> [@cerise](#):
>
> What is missing here?

[`OneShot.cancel(true)`](https://github.com/keyboardio/Kaleidoscope-OneShot#cancelwith_stickies) 😉

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

---

<div class="post-metadata">

**Author:** ![cerise](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cerise](https://community.keyboard.io/u/cerise)\
**Post date:** [July 2, 2018, 7:24am UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703/3 "2018-07-02T07:24:43Z")

</div>

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

regards, jo

---

<div class="post-metadata">

**Author:** ![cerise](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cerise](https://community.keyboard.io/u/cerise)\
**Post date:** [July 2, 2018, 11:35am UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703/4 "2018-07-02T11:35:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [July 2, 2018, 11:38am UTC](https://community.keyboard.io/t/how-to-clear-sticky-oneshot-modifiers-and-layers/1703/5 "2018-07-02T11:38:20Z")

</div>

> [@cerise](#):
>
> 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.

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

Thank you!
