class func addGlobalMonitorForEvents(matching mask: NSEvent.EventTypeMask, handler block: @escaping (NSEvent) -> Void) -> Any?{
print(\"this inside add
To enable AXIsProcessTrusted()
in your app you need to go to your macOS system preferences, open Security and Privacy
, click on Accessibility
, click on the plus sign to add your app to the list off apps that can control your computer. You might need to click at the padlock and type your password to unlock your settings.
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("AXIsProcessTrusted:",AXIsProcessTrusted())
NSEvent.addGlobalMonitorForEvents(matching: .keyDown) {
self.keyDown(with: $0)
}
}
override func keyDown(with event: NSEvent) {
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
case [.command] where event.characters == "1", [.command, .shift] where event.characters == "1":
print("command+1 or command+shift+1")
default:
break
}
}
}