Double Tap Cmd/Opt/Shift/Control as Hotkeys

Hello Frank

I am currently working on a new post of a Submacro and a Subroutine checking for things like a held fn key but this will not be ready for you in time.

In the time you have to wait you can of course try something your self borrowing the ASObjC code posted in the OP of my Multi-Press Templates Post.

If I remember it correctly it has a routine for watching the fn key built in so you can use it as it is for your purpose.

If you have any questions about that piece of code just ask me

Greetings from the sunny city Wetzlar in Hessen :wink::sunglasses:

Tobias

1 Like

Thanks Tobias! As I said, I use BTT for this. The app treats fn like all other modifiers.

BTT
image

KM
image

I have long been aware that one automation app can not do everything. The combination of KM and BTT is perfect. What one app can't do, the other can. :smiley:

1 Like

Because Fn is not, in Apple's terms, a modifier key, utilities that value compatibility/stability and so only use Apple's published public APIs won't know when it is pressed.

Some utilities go beyond those APIs, working "behind the scenes", and offer more functionality -- but there's always a risk of sudden breakage when Apple quietly change something.

Yes, Apple do also change the public APIs -- but that's usually either accidental and quickly reverted, or publicised enough in advance that developers can make changes in readiness. Although I'm sure @peternlewis has plenty of war stories from the times that process hasn't worked as advertised...

1 Like

Thanks @Nige_S, I realize that. But that shouldn't stop a problem solver like you from thinking about what @noisneil suggested. :smiley:

"you can use the state of any key as a global condition which, in practical terms, feels a lot like using a modifier."

I have tried this as well as I can. Unfortunately, since I can do almost nothing, my solution is pretty much useless. But it works, which at least proves that the basic idea could be implemented.

Suppose "f" is to be used as a "modifier". Eg f + j shall trigger a macro without typing "f" or "j". But of course "f" and "j" typed alone should be these letters.

My ridiculous macro below works. In addition it needs the macro "j" long press, does nothing. Short press = j.

If you or someone would implement the idea correctly, maybe someone can even use this. :joy:

F + J Down = Any Action (nothig ist typed).kmmacros (5.6 KB)


Yes and no.

Say, for example that Keyboard Maestro tried to do this with the Fn key as a modifier.

It can track the state of the Fn key, and know if it is down or up. That's fine.

So you have a hot key trigger active for say Fn-A. But since Fn is not a modifier, that means the hot key trigger would actually be for A, and then when the trigger fired, Keyboard Maestro could check whether the Fn key is down or not. If it is it runs the macro. That's actually probably all doable.

But what if the Fn key is not down. The A key has already been swallowed by the system, and sent to Keyboard Maestro as a hot key. There is no getting out of that without problems. Keyboard Maestro cannot then type an A or add an A to the event queue, because if it did it would end up being out of sequence. For example, you type "A", and "B" in quick succession, so the event queue as "A" and then "B" in it, and then the "A" is processed, swallowed, sent as a hot key, decided that there is no Fn key pressed, added to the event queue, which then has "B" and "A" in it, and assuming the hot key was then disabled for a short (but unknown) amount of time, you would get the out of order sequence "BA".

I understand, and I've found that fast typing can sometimes be an issue with fairly complex macros, but is that really true in practice for something as simple as a single key up/down check? I've tested the same detection idea with keys other than Fn and haven't found it possible to type fast enough for the sequence to be disrupted.

If I hit FnG while capturing a hotkey trigger, KM sees it as just G.

When it comes to triggering the macro, FnG does nothing but G will trigger the macro.

If Fn were ignored as a trigger the way it is ignored when a trigger is captured, then using it as a pseudo-modifier would be feasible.

I'm probably seeing something entirely backwards, but that's how it appears to me.

You got me thinking, so I tried capturing the Fn as a hotkey using the USB Device Key and got this:

2023-04-21_15-22-41

Now, when I press the Fn, the macro triggers!

Note: Everything I said in Post 3 above still applies - so YMMV.

I was referring specifically to hotkey triggers, whereas you captured it as a USB device key. That works, just as with any key, and can be used to capture the Fn key state as a variable like this:

Fn - Detect.kmmacros (22 KB)

Macro screenshot

The problem is that, even though Fn isn't accepted as part of a hotkey trigger, holding Fn does affect how KM sees other triggers.

Holding Fn and hitting G will be captured by KM's trigger input field as just G. So we might expect that holding Fn has no bearing on G as a hotkey trigger. However, Fn+G will not trigger the macro but G alone will.

This is unfortunate as it precludes the use of the above detection macro.

What seems to work somehow is this.

fn down/up shows/hides a palette, but the single key trigger of a macro on the palette is a string.

eg fn + j = left arrow

But you could do that with any key (except for one you want to use for something else, obviously!). Go wild -- plug in an external Apple Extended Keyboard and have an extra 100+ USB Device key triggers to play with!

1 Like

I might be utterly wrong here, because of Device Key triggers passing through to the frontmost app, rather than being swallowed in the way that hot key triggers are. I'll have to find an external kb and have a play...

Yes, Nige, I didn't want to tell you so as not to disappoint you :innocent:

I'm also interested in this function :slightly_smiling_face:

Further to this whole "Fn is not a modifier" thing, it seems Apple is taking a more active role in “owning” the Fn key for its own purposes.

See:

https://mjtsai.com/blog/2023/05/02/fn-key-reserved-for-system-applications/

2 Likes

But it has got me wondering. I mean, the reason vi[m] can have single keys that either type letters or perform actions is the different modes.

All we need to do is enable/disable single-key triggered macros depending on what "mode" we put our Mac in...

Right. Another "mode" could be activated with a macro group or a palette. But how to do that without disturbing the normal writing flow?

If you write slowly, you can solve this well with a multipress macro. In this case letters are typed when releasing the key and macros are triggered when holding the key a little longer. For fast typists this is known to be a disaster. :cold_face:

I wonder what it would be like if all letters were typed when the key is released. Theoretically, there shouldn't be any letter twists then. And you could easily trigger macros. But how does that feel for normal typing? Maybe I'll try that out :joy:

The original question was how to imitate a shortcut with fn + letter. @noisneil has described the problem well. A solution with a palette does not work either. Unless you choose a string, which is not really a good solution.

This is only relevant if you use the Apple Keyboard Shortcuts system. :wink:

Well, the real power of vi[m] "control keys" comes from being able to do things like 10j to go 10 characters back, 100l to go 100 lines down, etc. So while having to type something like Fn10j⎋ does break the flow, it's not as bad as mashing an arrow key multiple times.

Agreed and agreed. I'm off on another tack, for another time.

That's true, of course. The best you could do with KM would be a palette with single key triggers. For example, "0" would stand for 10 lines up. "0" long pressed for 10 lines down ... or something similar :slightly_smiling_face: