###
记录下APC工具的制作过程
模拟点击
首先需要开启系统辅助权限
let opts = NSDictionary(object: kCFBooleanTrue,
forKey: kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString
) as CFDictionary
guard AXIsProcessTrustedWithOptions(opts) == true else { return }
实测没啥用
发送点击事件
// 鼠标左键按下
let mouseDown = CGEvent(mouseEventSource: nil,
mouseType: .leftMouseDown,
mouseCursorPosition: CGPoint(x: 200, y: 300),
mouseButton: .left
)
mouseDown?.post(tap: .cghidEventTap)
// 鼠标左键抬起
let mouseUp = CGEvent(mouseEventSource: nil,
mouseType: .leftMouseUp,
mouseCursorPosition: CGPoint(x: 200, y: 300),
mouseButton: .left
)
mouseUp?.post(tap: .cghidEventTap)
//添加系统键盘监听
NSEvent.addGlobalMonitorForEvents(matching: .keyDown, handler: {
[unowned self] event in
// num1:18, num2:19
if event.keyCode == 18 {
// self.startAction()
}
})
OpenCV图片匹配
GitHub下载官方OpenCV, 使用Platform/osx/build_framework.sh 制作动态库。然后创建os x cocoa应用程序,一直build不过,从网上下了个模板可以跑。osx 命令行可以跑动。估计是build setting c++相关配置选项没搞正确。
截图工具
screencapture -t pathOfSaveFile
使用pipopen()调用系统命令即可。