Type String press one key then another, Fn " "

As per a previous post I am attempt to migrate from Karabiner. So i’m trying to keep it as similar as possible so that there is less issues, I realise that I might need to change them altogether.
However one handy shortcut I made was to press and release the fn key then tap any other key as a hot key within 500ms so as to run a different script.

Is this possible?

Thanks

Matt

I may have done it, let me know if there is something Flawed in this please

Matt

So that is flawed. I need conditions added so to pause Until any key is pressed,if 9 do this if 8 do that etc…

Maybe like this, with a trigger on REGEX

again I could be wrong.

If you are open to using another key instead of the fn key, then it is very easy.
I have many macros with a typed string trigger pattern like this:
;\d
(a RegEx)
Obviously I'm using the semicolon ; in place of the fn key, but you could choose any non-modifier key you like.
The \d is a RegEx for any number. Then in my macro I get the %TriggerValue%, and extract the last character, and use that in a Switch or Case action (KM Wiki).

I find this works very well. In fact, for me, I find the ; much easier to type than the fn.


Here's another thought.  Since you already have Karabiner, you could use it to remap the CapsLock key to the hyper-modifier key (⌘⌃⇧⌥), and use that with any other key as a hotkey trigger in KM.

Perhaps something like:

  • Repeat 1000 times (timeout without notification as appropriate)
    • If Key 8 is down
      • Do something
      • Break from loop
    • If Key 9 is down
      • Do something
      • Break from loop

etc.

I assume you know best Peter, but I have a strong aversion to tight computer loops like this.
I fear there is good opportunity to do any of these:

  • Lock-up the Mac, requiring a cold shutdown, losing some/lots of unsaved data.
  • Cause high-cpu usage, denying use of all other apps

I would not use this method unless there was no other way, and I absolutely had to have the functionality.
In this case, if use of the Karabiner-style fn key is a must-have, I'd program Karabiner to generate a certain combination of modifier keys when the fn key is held down longer than X. Then the user could press additional keys that would trigger a KM Macro.

But that's just me . . . :wink:

Yes, for other similar situations, I would add a Pause in the loop. And, as I mentioned, in this case you set the Repeat loop to have a short timeout (a few seconds at most), and thus the loop cannot continue for too long, and it can only ever do something once.

There are alternatives of course, like setting a variable and then using a switch statement, but it requires duplicate so it has its own programatically drawbacks.

Yep, I get that. But when a less knowledgeable, less experienced user is trying to set this up, mistakes can and will happen. Over the years, I have seen many infinite, tight loops, and have even created one or two myself. :wink:

Just sayin' that, IMO, it is best to avoid using them at all if you can, and look for other solutions.

This too seams a clean way to do it. I've added the timeout too. only needs to run a for second.

Repeat 1000 times (timeout without notification as appropriate)
If Key 8 is down
Do something
Break from loop
If Key 9 is down
Do something
Break from loop

I've done this but I spotted that break from loop can apply to all macros too.
Which would be better
Method A

Repeat 1000 times (timeout without notification as appropriate)

If Key 6 is down
Do something
Break from loop
If Key 7 is down
Do something
Break from loop
If Key 8 is down
Do something
Break from loop
If Key 9 is down
Do something
Break from loop

Or Method B and write one for each key? I prefer method B as each key would look less complicated and not too long.

Repeat 1000 times (timeout without notification as appropriate) 1 sec
If Key 6 is down
Do something
Break from loop Cancel all macros

A totally different solution if I understand the problem and we have relaxed the constraint to use the fn key…

Create any number of macros triggered by the same hotkey, say “’” (or by a string),
Each macro name begins with a different letter,
Press the hotkey, up pops the menu, press the first letter of the macro name.

Can be done quickly ignoring the popup.

1 Like