下面是我的简单AppDelegate.swift类。
// AppDelegate.swift
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSEvent.addGlobalMonitorForEventsMatchingMask(NSEventMask.KeyDownMask, handler: keyDown);
}
func keyDown(event:NSEvent!) {
print("key down is \(event.keyCode)");
}
}
为什么不打印按键事件?我想念什么?我尝试搜索周围,但无法解决。
根据NSEvent.h
上addGlobalMonitorForEventsMatchingMask:handler:
:
与密钥相关的事件仅在启用了可访问性或信任您的应用程序可访问性的情况下才受到监视(请参阅AXUIElement.h中的AXIsProcessTrusted)。请注意,对于发送到您自己的应用程序的事件,不会调用您的处理程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句