3 ms·
Detecting an alt-key push even when it's not an active window, and editing the selected text field are both accessibility permissions. Thanks for the info abou
by tornato7 3y ago
Detecting an alt-key push even when it's not an active window, and editing the selected text field are both accessibility permissions.
Thanks for the info about your app. It looks great!
- alin23 3y agoEditing 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.