Combining mouse and escape in 1 key

There have been several posts similar to this one, but I think my wishlist is unique so far.

My goal:

When tapped: press escape
When held: mouse layer
when double tapped: toggle mouse layer

I came up with this macro:

ifDoubletap toggleLayer mouse
ifPlaytime 450 final holdLayer mouse
tapKey escape

And escape works, and it goes into mouse mode on double tap, but it won’t exit mouse mode if you double tap again. Also the holdLayer doesn’t seem to work either.

Any thoughts on what I’m doing wrong?

Why don’t you do a ifDoubletap final toggleLayer mouse? It would be the last action you want to be executed on the second tap of a double tap, wouldn’t it?

For the ifPlaytime you need to wait first, because otherwise the 450 ms will never be reached as the macro runs through.

See this older post of mine for an example on how to detect multiple and long presses on a key: How many single key modifier/combination possible? - #6 by maexxx

You need to map another macro to untoggle the layer in that layer.

As for the ifPlaytime, I suggest replacing it with ifSecondary final holdLayer mouse.

Also, the “toggle” part is a misnomer. It actually locks the layer only. (I tried to follow the Agent terminology and didn’t realize the semantic incosistency.)

Thanks nice people!

OK I figured it out! I have to have 2 macros, one for base layer and one for mouse layer.

Mousekey base layer

ifDoubletap final toggleLayer mouse
ifHold holdLayer mouse
tapKey escape

Mousekey mouse layer

holdLayer mouse
unToggleLayer

This works! If you don’t have the second macro you can’t get out of mouse mode after double tap.

Thanks again!

Doesn’t your Mousekey base layer macro cause escape to be tapped after releasing a held mouseLayer, or when beginning a double-tap? Might not be desired in some circumstances.

Good Catch pcooke9,

Yes, you are correct. Double tapping to exit mouse layer does also send the escape key as well.

Is there a way to fix that? If not, I’ll live with it.

Idk how to suppress escape when double-tapping, but I think by replacing ifHold holdLayer mouse with ifSecondary final holdLayer mouse, you can stop it from triggering when releasing holdLayer mouse. Note that depending on your “Typing behavior → Secondary roles” settings, when using ifSecondary final holdLayer mouse, the mouse layer might not activate unless you hold the mouse key and also simultaneously use another key that’s mapped on the mouse layer. If you hold the mouse layer key without tapping another key, it might tap escape when released.

Sorry, that’s the best I can do. I’m a bit derpy with macros. :woozy_face:

Yes, just use final, then it’s the last command to be executed, as in:

ifHold final holdLayer mouse

Thanks again!

Neither option seems to work. There seems to be 2 problems actually:

when I double tap to go into or out of mouse mode, I get an esc key pressed. So it happens with both macros that run, I get an esc key pressed. The double tap to exit mouse mode seems to be the weirdest, since that macro should never run I wouldn’t think, since I am in the mouse layer when I double tap.

If it matters I’m on an original UHK 60 with firmware 15.0.1 under MacOS. I love the keyboard generally, but I’m just getting back to using it, after traveling for many years and not having any external keyboard.

Where I’m at macro wise:

mouse key base layer:

ifDoubletap final toggleLayer mouse
ifHold final holdLayer mouse
tapKey escape

mouse key mouse layer:

holdLayer mouse
final unToggleLayer

Regarding Max’s suggestion, the final solves just the escape from mouse layer hold, but not that one from the doubletap.

ifGesture can be used to look into the future and with thisKeyId argument acts as a doubletap.

I think this should do the trick:

ifGesture $thisKeyId final toggleLayer mouse
ifHold final holdLayer mouse
tapKey escape

and

unToggleLayer

There is no doubletap logic related to exitting the mouse layer.

It is the unToggleLayer mapped in the layer that does it.

First macro (on base layer): If you double tap to switch to the mouse layer, then the first tap will not be considered a ifDoubleTap (because only the second tap will trigger this), but instead will go through to tapKey escape. The second tap of your double tap will then trigger the ifDoubleTap and toggle to the mouse layer. As a result the host computer will receive an Escape key before the mouse layer is toggled.

Second macro (on mouse layer): If you double tap to switch back from the toggled mouse layer, then the first tap will already run your macro, resulting in untoggling the layer. The second tap of your double tap then is seen as the first and only tap on the macro on the base layer, resulting in the tapping of Escape.

As @kareltucek already suggested, if you want to capture a double tap without any action on the first tap, you need to use ifGesture. This will wait (up to a timeout) for more keys, and if they are in the list, the if clause will trigger. The keys pressed will be swallowed, and your action will be taken (toggle to mouse layer). This will fix the first macro.

For the second macro, if you want to ensure that both a single tap as well as a double tap will untoggle the mouse layer without sending an extra Escape, then you will have to catch the double tap with ifGesture there as well, so something like:

ifGesture $thisKeyId noOp
unToggleLayer

Ah! you and @kareltucek are correct! This totally works!

The problem with ifGesture, it takes a while to get that escape key to push. Likely as @maexxx suggests, it’s waiting around to see if I’m going to push more keys.

That delay is annoying, so I’ll trade an extra esc when double tapping into mouse mode instead.

Thanks people! You are fabulous, and I learned a thing or five!

You can adjust the time that ifGesture waits using timeoutIn in ms.

ifGesture timeoutIn 150 $thisKeyId final ...

I’m confused as to why you want to double-tap to leave the mouse layer. Normally, you’d double-tap to toggle the layer on, and then you only need to single-tap to leave it.

Unless… Are you still wanting tapKey escape to work when you’ve double-tapped (locked) into the mouse layer?

1 Like

Thanks for the replies and help! A family member went into the hospital(intensive care) so I’m a bit distracted. I’ll revisit this at some later date, but for now I’m good enough.

Sorry to hear that. :people_hugging: