Hacker News new | past | comments | ask | show | jobs | submit login

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.



Thanks! Yes, to be clear I was rewriting it in Swift which I'm new at, so I appreciate the expert advice there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: