# Dropping layer shift while holding other keys

**URL:** <https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592>\
**Category:** Programming\
**Created:** [October 29, 2017, 3:01pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592 "2017-10-29T15:01:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [October 29, 2017, 3:01pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/1 "2017-10-29T15:01:47Z")

</div>

While attempting to get an overview idea of how Kaleidoscope works, I came across the following in `layers.h`:

> <https://github.com/keyboardio/Kaleidoscope/blob/6d3828c1345351fecc7b8ae9b50bb73842aa2214/src/layers.h#L18>

Specifically:

`…if you hold a key on a layer, release the layer key but continue holding the other, we want for the layered keycode to continue repeating.`

Why do we want that? It’s not what happens when modifier keys are released, so why should it work that way with layer shifts? To me, that’s counterintuitive, and I definitely don’t want it unless there’s some very good reason for having it. Is there a particular use case that this was done for?

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [October 29, 2017, 3:11pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/2 "2017-10-29T15:11:20Z")

</div>

Is it because we want the key that’s shifting layers (i.e. `ShiftToLayer(X)`) to not get changed to something else in that new layer?

---

<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:** [October 29, 2017, 4:10pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/3 "2017-10-29T16:10:00Z")

</div>

The primary reason for this were the arrow keys: if one released the layer key a tiny bit sooner than the arrow key, they’d get all kinds of `hjkl` all over the place. This way, they’ll just get an extra arrow or so. For some of the background, see [here](https://github.com/keyboardio/Kaleidoscope/pull/152), and a couple of the later pull requests that have to do with layers (apologies, don’t have the resources right now to link them all).

I seem to recall we experimented with just masking keys on layer change, but that didn’t feel right either, and as far as I remember, had some consequences we did not deem desirable.

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [October 29, 2017, 5:31pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/4 "2017-10-29T17:31:01Z")

</div>

> [@algernon](#):
>
> …if one released the layer key a tiny bit sooner than the arrow key, they’d get all kinds of hjkl all over the place.

All over the place? I’d expect just one. And I’d also chalk that up as a (human) typing error.

The more I explore the Kaleidoscope code, the more puzzling things I find in there. I hope I’m not annoying anyone by bringing up my questions here.

---

<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:** [October 29, 2017, 7:11pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/5 "2017-10-29T19:11:35Z")

</div>

I wouldn’t chalk this up as human typing error, but that’s me. There were other issues as well, like the one I linked to.

---

<div class="post-metadata">

**Author:** ![craigdissel](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@craigdissel](https://community.keyboard.io/u/craigdissel)\
**Post date:** [October 29, 2017, 7:46pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/6 "2017-10-29T19:46:07Z")

</div>

I’m in favor of the behavior that “releasing modifiers and/or layer keys doesn’t change keys that are currently held”. I essentially never hold a modified key, then release the modifier with the intent that the un-modified key should then register. However, I recognize that others can have other opinions.

Also, it’s convenient to hold Fn and (e.g.) J for down arrow, and then be able to release Fn and just hold J to keep going down.

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [October 29, 2017, 8:36pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/7 "2017-10-29T20:36:57Z")

</div>

> [@craigdissel](#):
>
> I essentially never hold a modified key, then release the modifier with the intent that the un-modified key should then register.

On just about any keyboard, pressing and holding `shift`, then `A`, then releasing them in the same order will result in `AAAAAaaaa`. I don’t see why I should expect something different from layer changes where a key is held down to activate the layer (that’s really what `shift` does from the point of view of the end user, after all).

I do think it’s reasonable to have a short “grace period” so that if someone releases both keys (almost) simultaneously, you avoid spurious unintended keypresses. In my `shift`+`A` example, key repeat rate limiting generally keeps that from happening.

> [@craigdissel](#):
>
> Also, it’s convenient to hold Fn and (e.g.) J for down arrow, and then be able to release Fn and just hold J to keep going down.

That still strikes me as taking advantage of a bug as a feature, and I don’t want it to work that way, but I won’t try to convince anyone to change it. I’m resigned to having to rewrite Kaleidoscope on my own if I really want it to behave in a way that makes sense to me.

---

<div class="post-metadata">

**Author:** ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)\
**Post date:** [October 29, 2017, 10:31pm UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/8 "2017-10-29T22:31:43Z")

</div>

> [@merlin](#):
>
> On just about any keyboard, pressing and holding shift, then A, then releasing them in the same order will result in AAAAAaaaa. I don’t see why I should expect something different from layer changes where a key is held down to activate the layer (that’s really what shift does from the point of view of the end user, after all).

That was, in fact, our original behavior for layer switches. Logically, what you way makes perfect sense. When actual users started using it, they found it to be incredibly frustrating to use.

I’d be happy to look at patches to let the behavior be configurable. My recollection is that there was some difficulty in doing that, but I don’t recall what it was.

IIRC, part of the issue is that AAAAAaaaa is limited by key repeat rates on the host, but when we’re doing this on the keyboard, left arrow to H is treated as a new press by the computer and there is _no_ timeout whatsoever.

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [October 30, 2017, 12:17am UTC](https://community.keyboard.io/t/dropping-layer-shift-while-holding-other-keys/592/9 "2017-10-30T00:17:00Z")

</div>

> [@jesse](#):
>
> IIRC, part of the issue is that AAAAAaaaa is limited by key repeat rates on the host, but when we’re doing this on the keyboard, left arrow to H is treated as a new press by the computer and there is no timeout whatsoever.

I think I’m caught up on the history of this via GitHub issues now. If I got one of those spurious “h” characters, I’d consider that my own error, but it’s clearly reasonable to treat it as something the keyboard should protect against. I’d rather have the held key become inactive, but I really don’t have a problem with the current behaviour. I have been convinced.
