相关疑难解决方法(0)

你如何在Swift中使用CGEventTapCreate?

有没有人设法让这个功能在Swift中工作?

这是去年的参考SO帖子:使用CGEventTapCreate在Swift中使用参数麻烦

Apple Doc:https://developer.apple.com/library/prerelease/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/func/CGEventTapCreate

以下是CGEventTapCallBack的定义方式:

typealias CGEventTapCallBack = CFunctionPointer<((CGEventTapProxy, CGEventType, CGEvent!, UnsafeMutablePointer<Void>) -> Unmanaged<CGEvent>!)>
Run Code Online (Sandbox Code Playgroud)

以下是我编写块的方法:

let eventTapCallBackBlock : @objc_block
(CGEventTapProxy, CGEventType, CGEventRef, UnsafeMutablePointer<Void>) -> CGEventRef =
{ (eventTapProxy: CGEventTapProxy, eventType: CGEventType, event: CGEventRef, refcon: UnsafeMutablePointer<Void>) in
  return event
}
Run Code Online (Sandbox Code Playgroud)

然后我用回调参数调用了CGEventTapCreate unsafeBitCast(eventTapCallBackBlock, CGEventTapCallBack.self)

我得到了有效的CFMachPortRef回复,但在运行时我在第一个事件上遇到了访问冲突异常.它似乎"似乎"我在当前发布状态下接近迅速解决方案.

使用Xcode版本6.4

macos core-graphics cgeventtap swift

8
推荐指数
1
解决办法
3176
查看次数

标签 统计

cgeventtap ×1

core-graphics ×1

macos ×1

swift ×1