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!) }
You can do that using something like:
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.