# Alternative to DualUse that doesn't use timeout?

**URL:** <https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613>\
**Category:** Plugins\
**Created:** [October 30, 2017, 5:27pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613 "2017-10-30T17:27:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 5:27pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/1 "2017-10-30T17:27:29Z")

</div>

DualUse waits for a “timeout” before switching to the secondary use.

I’m looking for an approach where:

1. Key pressed alone: Escape
2. Key held down then a second key pressed: Treated as “ShiftToLayer”

So there’s no timeout involved, only a “by itself” or “with others”.

I’m thinking I could achieve this with “MagicCombo”, but writing an entire layer with MagicCombo would be unwieldy.

Any advice? Thanks!

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 30, 2017, 5:37pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/2 "2017-10-30T17:37:06Z")

</div>

If I understand what you mean, I _think_ you could do something like this by writing a custom event hook that checks if the given key is held down in addition to another key and activate a shift to layer? Basically, write your own plugin, which is obviously not a very helpful answer 😕

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 7:16pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/3 "2017-10-30T19:16:26Z")

</div>

Yeah… C++ isn’t my strong suit. I mostly copy/paste from the examples to put together my .ino files 😃

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 7:18pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/4 "2017-10-30T19:18:30Z")

</div>

if it helps anyone understand, Karabiner calls this behavior: "to\_if\_alone"

> <https://github.com/tekezo/Karabiner-Elements/blob/master/examples/spacebar_to_shift.json#L23>

---

<div class="post-metadata">

**Author:** ![john](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/john/32/72_2.png) [@john](https://community.keyboard.io/u/john)\
**Post date:** [October 30, 2017, 7:36pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/5 "2017-10-30T19:36:32Z")

</div>

Right, but Karabiner also has a timeout setting for that – `"basic.to_if_alone_timeout_milliseconds": 1000` in my config.

Based on my noob-level understanding of how all this stuff works, the keyboard is basically periodically sending time-based snapshots of which keys are pressed at that particular moment – so there’s not really a “by itself” or “with something else”, there’s just “within approximately the same interval, give or take”, or “outside that interval, give or take”. Overall, everything is happening fast enough on human-perceptible timescales that you can effectively treat it as “by itself” or “at the same time”, but on an implementation level, that timeout has to be there.

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 7:42pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/6 "2017-10-30T19:42:41Z")

</div>

That makes sense. I guess I’ll just have to keep playing with the time\_out then. The thumb keys are so darn convenient that I press the second key too darn fast. 😇

---

<div class="post-metadata">

**Author:** ![john](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/john/32/72_2.png) [@john](https://community.keyboard.io/u/john)\
**Post date:** [October 30, 2017, 7:48pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/7 "2017-10-30T19:48:04Z")

</div>

Yeah, I’m pondering experimenting with reducing it to 800 or so, but I’m also at the point where I need to quit _changing_ things lest I never actually learn to comfortably **use** it… 8^)

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 30, 2017, 7:49pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/8 "2017-10-30T19:49:10Z")

</div>

I think the “plugin” you’d have to write would be fairly simple - set a flag when the key is pressed, clear it when released, if another key is pressed while the flag is set, switch to the layer until the next keypress…kind of the opposite of [this](https://github.com/ilianaw/Model01-Firmware/commit/7dad53bf1855e68a4c93a1686cad5e75b539cb0b) handy thing I saw someone post on Mastodon.

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 7:51pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/9 "2017-10-30T19:51:29Z")

</div>

Thanks, that’s insanely helpful.

---

<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 30, 2017, 11:18pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/10 "2017-10-30T23:18:53Z")

</div>

You are not the first one to have a timeout-less `DualUse` desire, so there appears to be a reasonable demand for it.

One of the reasons I didn’t write one such yet, is that there are a few edge cases I couldn’t figure out (I don’t use `DualUse` myself, that’s probably why). Like, say, you want to use the second behaviour of shifting to a layer, and you hold down this key, then a second or so later, press another key. Without a timeout, how would you prevent `Esc` from being input? Or is it ok if we get a bit of `Esc`? Personally, I would find that very frustrating to use, and would prefer if `Esc` didn’t fire in this case. But I’m unsure how to solve that without a timeout.

@merlin had some thoughts on this, at [DualUse#1](https://github.com/keyboardio/Kaleidoscope-DualUse/issues/1) and [DualUse#7](https://github.com/keyboardio/Kaleidoscope-DualUse/issues/7), but I don’t have the mental capacity to think about his ideas deeper.

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 30, 2017, 11:51pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/11 "2017-10-30T23:51:21Z")

</div>

@algernon would it help if you could “force” the following restrictions?

- “held” must be a ShiftToLayer key
- “tap” must be a Regular key (like Escape, Tab, etc)

Those are my only scenarios for DualUse.

---

<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 31, 2017, 12:07am UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/12 "2017-10-31T00:07:56Z")

</div>

Yeah, with those restrictions, it can be made to work. If you can come up with a good name for the plugin, I can give it a go on ~Wednesday. Should be a reasonably simple endeavour (anyone else is free to beat me to it, mind you!)

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 31, 2017, 12:10am UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/13 "2017-10-31T00:10:59Z")

</div>

I’d name it something like “ToIfAlone” so if someone is coming from Karabiner (like me), they’ll find it right away 🙂

---

<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 31, 2017, 1:17am UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/14 "2017-10-31T01:17:49Z")

</div>

I’ve been thinking about DualUse (or similar) a lot recently, but I haven’t had much time in front of a computer or with pen and paper to work out the details.

I am quite convinced that I want a timer, but only as part of the mechanism, both so that DualUse modifiers can be used to modify mouse clicks and to minimise or eliminate unintended input from overlapping key presses on both ends.

I started with the idea of not including the DualUse key or any subsequently pressed keys in the report until either the DualUse key or the subsequent key is released — if the DualUse key is released first, then include it as a printable character in the next report, then include the subsequent key. If the other key is released first, both get included in the next report, but with the DualUse as a modifier.

That becomes trickier than I originally thought, however, and gets really hairy if the user holds down the DualUse key, then presses and holds more than one other key, too. That in mind, I thought that the decision should be made no later than the second press or release event after the DualUse key is pressed. Anything other than the DualUse key being released would result in the modifier behaviour. Even then, what if there are two keys that get pressed so nearly simultaneously that they both register in the same scan cycle? And what if one of the subsequent keys is itself a DualUse key (that would be a typical use case for my plan, in fact, since the idea is to have one modifier of each type on each finger for ease of chording multiple modifiers)? And there’s also the possibility of overlap with keys pressed before the DualUse key, too.

I suspect that the behaviour I want may actually be possible with timers only, but they’d have to be quite short (maybe 100ms at most), and would also involve some non-trivial overlap detection.

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 31, 2017, 1:42am UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/15 "2017-10-31T01:42:16Z")

</div>

I started trying to take a crack at it…not quite working, but I’ll try to finish it off tomorrow [https://github.com/jamesnvc/Kaleidoscope-ToIfAlone](https://github.com/jamesnvc/Kaleidoscope-ToIfAlone)

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 31, 2017, 5:55pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/16 "2017-10-31T17:55:57Z")

</div>

Update: plugin linked above is working! I will update with a README shortly. My first Kaleidoscope plugin 😃

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 31, 2017, 7:10pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/17 "2017-10-31T19:10:24Z")

</div>

Awesome! Installed and totally working great!!! 🎉

> <https://github.com/johnlindquist/Model01-Firmware/blob/master/Model01-Firmware.ino#L325>

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 31, 2017, 7:46pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/18 "2017-10-31T19:46:19Z")

</div>

Hooray! Glad to hear it 🙂

---

<div class="post-metadata">

**Author:** ![johnlindquist](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/johnlindquist/32/587_2.png) [@johnlindquist](https://community.keyboard.io/u/johnlindquist)\
**Post date:** [October 31, 2017, 9:30pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/19 "2017-10-31T21:30:04Z")

</div>

Time to start filing bugs and feature requests 😇

---

<div class="post-metadata">

**Author:** ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)\
**Post date:** [October 31, 2017, 11:33pm UTC](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613/20 "2017-10-31T23:33:46Z")

</div>

Please do! Especially bugs, gotta squash those little creatures.

[Next page](https://community.keyboard.io/t/alternative-to-dualuse-that-doesnt-use-timeout/613.md?page=2)
