4 ms·
Editing the field definitely needs the permissions, but detecting Alt-key holding should not. You can do that using something like: var reactOnOptionKeyHe
by alin23 3y ago
Editing the field definitely needs the permissions, but detecting Alt-key holding should not.
You can do that using something like:
var reactOnOptionKeyHeld: DispatchWorkItem? { didSet { oldValue?.cancel() } }
NSEvent.addGlobalMonitorForEvents(matching: .flagsChanged) { (event) in
guard event.modifierFlags == [.option] else {
reactOnOptionKeyHeld = nil
return
}
reactOnOptionKeyHeld = DispatchWorkItem {
// start recording
}
// schedule to run if held for at least 1 second
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: reactOnOptionKeyHeld!)
}
I see you're using Python with pynput though, which is creating a full key listener so I guess that is why you need the permissions.
- tornato7 3y agoThanks! Yes, to be clear I was rewriting it in Swift which I'm new at, so I appreciate the expert advice there.