gpt4 book ai didi

swift NSEvent 不工作

转载 作者:IT王子 更新时间:2023-10-29 05:48:10 25 4
gpt4 key购买 nike

下面是我的简单 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)");
}

}

为什么按键按下事件没有被打印出来?我错过了什么?我试过四处搜索,但无法弄清楚。

最佳答案

根据 addGlobalMonitorForEventsMatchingMask:handler: 上的 NSEvent.h:

Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access (see AXIsProcessTrusted in AXUIElement.h). Note that your handler will not be called for events that are sent to your own application.

关于 swift NSEvent 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com