盛年不重来,一日难再晨,及时当勉励,岁月不待人。这篇文章主要讲述在appkit中禁用右键单击相关的知识,希望能为你提供帮助。
我目前在mouseDrag函数中接受nextEvent
while true {
guard let nextEvent = self.window?.nextEvent(matching: [.leftMouseDragged, .leftMouseUp, .rightMouseUp]) else {
continue
}
switch nextEvent.type {
case .leftMouseDragged:
self.cursorUpdate(with: nextEvent)
self.mouseDragged(with: nextEvent)case .rightMouseUp:
continuedefault:
self.mouseUp(with: nextEvent)
return
}
}
而我只是试图在持续时间内禁用右键单击。但是,通过此实现,右键单击只是排队并在循环结束后调用。
如何禁用正确的点击注册?
答案尝试将
.rightMouseDown
和.rightMouseDragged
添加到匹配的面具中。 .rightMouseDown
事件使AppKit显示上下文菜单。guard let nextEvent = self.window?.nextEvent(matching: [.leftMouseDragged, .leftMouseUp, .rightMouseDown, .rightMouseDragged, .rightMouseUp]) else {
continue
}
您也可以考虑切换到
NSWindow.trackEvents(matching:timeout:mode:handler:)
而不是编写自己的循环:window.trackEvents(matching: [.leftMouseDragged, .leftMouseUp, .rightMouseDown, .rightMouseDragged, .rightMouseUp], timeout: NSEvent.foreverDuration, mode: .eventTrackingRunLoopMode) { (event, outStop) in
guard let event = event else { return }
switch event.type {
case .rightMouseDown, .rightMouseDragged, .rightMouseUp: return
case .leftMouseDragged:
self.cursorUpdate(with: event)
self.mouseDragged(with: event)
case .leftMouseUp:
self.mouseUp(with: event)
outStop.pointee = true
default:
break
}
}
【在appkit中禁用右键单击】使用
trackEvents
让AppKit运行主运行循环,因此计时器和观察者可以继续射击(如果它们被安排用于.eventTrackingRunLoopMode
)。推荐阅读
- Android 9上的BiometricManager
- 如何在Android中停止可运行线程()
- java.lang.NoClassDefFoundError(部署到Google App Engine时无法初始化类net.sf.cglib.proxy.Enhancer。)
- Jquery在混合android中不起作用,但在网络中起作用
- 如何在Android中设置EditText的最大字符数()
- Android(如何从一组图像制作视频)
- MediaStore.EXTRA_VIDEO_QUALITY不适用于Android视频捕获
- 如何在Android Studio中使用YouTube API在Android应用中列出视频
- android studio模拟器无法播放视频