我为我的应用程序提供了一个全局热键,但是在调用它之后,它将寻找下一个单击的字母以更改其行为。问题在于,如果该字母是打开的,它仍会键入文本编辑器中。有没有办法阻止它继续下去?
编辑:这是我到目前为止的代码:
let options = NSDictionary(object: kCFBooleanTrue, forKey: kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString) as CFDictionary
let trusted = AXIsProcessTrustedWithOptions(options)
if (trusted) {
NSEvent.addGlobalMonitorForEvents(matching: .keyDown, handler: self.handler)
}
处理程序方法
func handler(event: NSEvent!) {
let key = event.keyCode
let flag = event.modifierFlags.rawValue
if waitForNextLetter {
waitForNextLetter = false
// don't let this letter be dispatched
}
if key == 0 && flag == 655650 {
waitForNextLetter = true
}
}