locationInWindow
The event location in the base coordinate system of the associated window.
Declaration
var locationInWindow: NSPoint { get }Discussion
This property applies to mouse events. For non-mouse events the value of this property is undefined.
With NSMouseMoved and possibly other events, the event can have a nil window (that is, the window property contains nil). In this case, this property contains the event location in screen coordinates.
In a method of a custom view that handles mouse events, you commonly use this property with the convert(_:from:) method of NSView to get the mouse location in the view’s coordinate system. The following code shows how to perform this conversion. The y coordinate in the returned point starts from a base of 1, and not 0.
NSPoint event_location = theEvent.locationInWindow;
NSPoint local_point = [self convertPoint:event_location fromView:nil];