gpt4 book ai didi

swift - 如何将 NSEvent 标记为已处理?

转载 作者:搜寻专家 更新时间:2023-11-01 06:30:26 26 4
gpt4 key购买 nike

我使用以下代码处理键盘上字母键的按下。

NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.keyDown) { event in
// code
}

然后如何将 NSEvent 标记为已处理,不允许系统和其他应用程序再次处理它?例如不允许在打开的文本编辑器中输入按下的字母?

最佳答案

你不能用 NSEvent 做到这一点。正如文档所述:

Events are delivered asynchronously to your app and you can only observe the event; you cannot modify or otherwise prevent the event from being delivered to its original target application.

您不是事件生成系统的一部分;您只是在运行循环中收到通知。

如果你想成为事件系统的一部分,在应用层之下,你需要使用CGEvent。参见 tapCreate(tap:place:options:eventsOfInterest:callback:userInfo:)。回调可以返回 NULL 以指示它已消耗该事件。

关于swift - 如何将 NSEvent 标记为已处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48135509/

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