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.
@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.
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.
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.
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.
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….
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
A KM Link button isn't a 'key'; it triggers a script that runs a macro. Anyway, yeah, not important.
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.
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 ?
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.