gpt4 book ai didi

swift - 在 'addLocalMonitorForEventsMatchingMask' 中将 NSEventMask 管道连接在一起

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

我有以下代码用于监听 View 外的鼠标事件(NSView 的子类)。这很好用,但我不知道如何将 NSEventMasks 通过管道连接在一起。我基本上想在 NSEventMask.LeftMouseDownMaskNSEventMask.RightMouseDownMaskNSEventMask.OtherMouseDownMask 上触发相同的事件监听器。

有谁知道如何将它们组合在一起,或者在 Swift 中是否可行?

工作代码

localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMask.LeftMouseDownMask) { (event: NSEvent) -> NSEvent? in

// Event handling...

return event
}

最佳答案

This answer可能对你有帮助。

简而言之,您现在可以使用数组,所以这似乎让编译器很高兴:

localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask([.LeftMouseDownMask, .RightMouseDownMask, .OtherMouseDownMask]) { (event: NSEvent) -> NSEvent? in

// Event handling...

return event
}

关于swift - 在 'addLocalMonitorForEventsMatchingMask' 中将 NSEventMask 管道连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34394550/

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