Swift newbie here.
I\'ve been having trouble with a task that should be trivial. All I want to do is get the x,y coordinates of the mouse cursor on-demand
You can get the current mouse location in this way:
Declare this in your view controller class:
var mouseLocation: NSPoint? { self.view.window?.mouseLocationOutsideOfEventStream }
Then, you can get the current mouse location and convert in your desired view coordinates:
if let currentMouseLocation = self.mouseLocation{
let pointInTargetView = self.**targetView**.convert(currentMouseLocation, from: self.view)
}