I've read https://wiki.keyboardmaestro.com/trigger/USB_Device_Key but I cannot say whether there is a KM action to detect whether the CAPS Lock key on my Apple Keyboard (with num pad) is activated (indicated by the green LED burning).
What I want to achieve is:
- If a variable SourceSegmentNoTags is ALL CAPS, press the CAPS Lock key.
At https://apple.stackexchange.com/questions/361373/toggle-caps-lock-programmatically-using-applescript I've found this script:
ObjC.import("IOKit");
ObjC.import("CoreServices");
(() => {
var ioConnect = Ref();
var state = Ref();
$.IOServiceOpen(
$.IOServiceGetMatchingService(
$.kIOMasterPortDefault,
$.IOServiceMatching(
$.kIOHIDSystemClass
)
),
$.mach_task_self_,
$.kIOHIDParamConnectType,
ioConnect
);
$.IOHIDGetModifierLockState(ioConnect, $.kIOHIDCapsLockState, state);
$.IOHIDSetModifierLockState(ioConnect, $.kIOHIDCapsLockState, !state[0]);
$.IOServiceClose(ioConnect);
})();
But on Catalina it only turns the CAPSLOCK on. As for now, I can live with that. I'll just have to remember to switch CAPSLOCK off manually.
Update: Tested on Big Sur too. Script only activates the CAPSLOCK, but doesn't deactivate it.