I'm using Swift and I'm trying to figure out how to control my macOS mouse with my iPhone. I figured that the first steps would be to programmatically move the MacOS mouse with a macOS app. I'm not sure what I'm missing or doing wrong.
import Cocoa
import CoreGraphics
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
typealias CGDirectDisplayID = UInt32
func CGMainDisplayID() -> CGDirectDisplayID{
return CGMainDisplayID()
}
func CGDisplayMoveCursorToPoint(_ display: CGDirectDisplayID,
_ point: CGPoint){
}
self.CGDisplayMoveCursorToPoint(CGMainDisplayID(),(25,400))
}
I get an error: "Expected Declaration" for self.CGDisplayMoveCursorToPoint(CGMainDisplayID(),(25,400))
(25,400)isn't aCGPoint, it's a tuple of type(Int, Int). You should also fix up your function name:static func moveCursor(toPoint point: CGPoint, onDisplay display: CGDirectDisplayID), and call it with:moveCursor(toPoint: CGPoint(x: 25, y: 400), onDisplay: CGMainDisplayID()). These functions don't make sense to be instance members ofViewController. I would recommend you add an extension ofCGDirectDisplayID, make it a free function, or make a new type to contain these functions.