Hotkey Triggers using Left/Right Modifiers

This stems from a request from @rob. According to @Frankb, this might be of interest to a few other people, so here it is...

These macros will determine whether a left or right modifier has been pressed and save that state as a global variable. I'm using my Macbook Pro's internal keyboard, so recapture the USB Device Key triggers if using something else.

L:R ⌥ - Detect .kmmacros (22.0 KB)
L:R ⇧ - Detect.kmmacros (22.0 KB)
L:R ⌘ - Detect.kmmacros (22.0 KB)

Now, when you want to trigger a macro using, for example the left ⌥ key, you can use an If/Else condition, like so:

L-R - Trigger Example (⌥).kmmacros (22 KB)

Macro screenshot

6 Likes

Hey Neil (@noisneil),

Didn’t know about that left or right modifier detection is possible with KM.

Many thanks for sharing this !!

Greetings from Germany

Tobias

1 Like

@Nr.5-need_input Most people didn't know that, I assume. One of @noisneil 's masterpieces. Note that you can also use it to replace Hyperkey (Caps Lock). eg Karabiner is no longer necessary for that.

Ah, and what I also didn't know is what @tiffle managed to do.

1 Like

Hello Frank (@Frankb)

That’s true - even though that he uses more less Hotkey combinations than probably most of the other folks here.

But I am not thinking about a replacement of Karabiner-Elements and the Hyperkey Mapping. I will try to use it to eventually extend the functionality in some way …

I will bookmark the topic you shared with me for later when I have the time for it to read. Thanks for that.

Greetings from Wetzlar, Hess

Tobias

Just remember that this is not generic, but keyboard (keyboard type?) specific -- so if you switch between internal and external keyboards you'll need to handle both.

1 Like

It's a shame this only activates Caps Lock and won't deactivate it. Would be really neat to be able to use it as Caps Lock and as Hyperkey at the same time.

Hello @Nige_S

A nice reminder from you !! Thanks for that …

With keeping Karabiner-Elements and doing a little bit variable handling and scripting with AppleScript in the JSON Rules of Karabiner-Elements this maybe might be possible putting the keyboard based Infos into a Global KM Variable.

Maybe there could be another (2nd) way if Karabiner-Elements still supports custom XML with nested AppleScript like in the good old days….

Greetings from Germany

Tobias

@noisneil Is it not possible to combine your macro with @tiffle's?

  • double tap = Caps Lock

  • pressed and hold = hyperkey (actually right control)

He has a stream deck, these are actually hotkeys too... but without modifiers :joy:

Link?

The SD can trigger hotkeys, but I don't use it like that for the mostpart. I mainly use it to directly call macros using the KM Link plugin.

Hey Neil

Frank was speaking about this kind of thing

My thoughts are maybe there maybe will be a way but it is a complex way - and not every case will work …

Greetings from Germany

Tobias

@Nr.5-need_input Exactly, that's what I meant.

Pressing a key, any key, could already be understood as a hotkey. It's just a question of definition. Not important, forget it :slightly_smiling_face:

I was actually having the same thoughts - on this kind of thing …. And my answer was just faster since I already had tiffle‘s example open spinning my head on how this might work

I can report that this works with BTT. I mean the switch between Caps Lock and Hyperkey. I rarely need this though.

Hey Frank

I use the Karabiner-Elements rule to switch Caps Lock to Hyperkey if pressed with any other key and use as Caps lock if pressed alone

On every one of my current macs

  • 13“ MacBook Pro mid 2010 with High Sierra and Karabiner-Elements v12.x

  • 27“ iMac 2020 with Monterey 12.3 and Karabiner-Elements v13.x

Keyboards are all Apple

  • MBP internal
  • Magic Keyboard gen 1
  • Magic Keyboard gen 2
  • Magic Keyboard gen 2 extended

All keyboards are working with every one of the both macs and the version of Karabiner-Elements….

That's the easy bit...

A KM Link button isn't a 'key'; it triggers a script that runs a macro. Anyway, yeah, not important. :+1:t3:

The reason I was interested in disabling Caps Lock was:

You don't need to switch Caps Lock to ⌃ in order to use it as a hyperkey. You can just use it as a USB Device Key, just as I am with the Left/Right Detect macros above.

Therefore, if Caps Lock is held while you hit another key, a macro would run. Once you release it, Caps Lock would be programatically disabled. If you just pressed it without pressing something else at the same time, it would simply function as the Caps Lock key. Anyway, it's a moot point as the AppleScript doesn't work.

Das habe ich mir schon gedacht :slight_smile: I also wanted to do it that way at first. But because I mainly use BTT and understand that best I use that.

But the button/key of your SD is, not important. :slightly_smiling_face:

Then you'll probably need Karabiner. However, you have given me an idea how to solve this with BTT, I'll test that....

I am sorry Neil but the code you linked to is not an AppleScript or what it should be - because of the calling of Apple‘s Frameworks - would be an AppleScriptObjective-C Script.

But here in this case it is JavaScript for Automation using Apple‘s Objective-C API

My thinking here is that the support of many API‘s is not at the same level for JXA as for AppleScript - and because of that fact maybe there will be possibly a way to fix the issue rewriting it as an AppleScriptObjective-C Script.

But I don’t know if that is true and even though that I am currently learning a lot in ASObjC - I still don’t know enough to rewrite it and prove it if I am right or not.

But maybe there are guys here who could test that - maybe @Nige_S or @ccstone ?

Greetings from Germany.

Tobias

I'm still using macOS Mojave, so I can't do much with this.

Point-to-note – AppleScriptObjC is part of AppleScript these days.

I'm and old fashioned AppleScripter (since 1993), so I still tend to discriminate between vanilla AppleScript and AppleScriptObjC – but really they're both part of the same scripting language (for a long time now).

I've relabelled the script slightly to make it more clear that it's JXA.

According the @ALYB the script does not toggle back OFF as of Catalina and Big Sur, although I cannot test this for myself.

Anyone wanting to work with it further should visit the Script Debugger Forum.

Although perhaps @CJK might want to revisit it.