0
override func mouseDown(with event: NSEvent) {
        
    let startPoint = event.locationInWindow
    print(startPoint) //for top left it prints (0, 900)

To my knowledge the screen's origin is defined as the top left corner of the screen. But NSView's mouse down event gives the screen's bottom left as the origin(top left coordinates are 0,900).

I have already tried using:

  self.convert(event.locationInWindow, from: nil)

But the results are the same.

Is there a way to convert these coordinates to screen coordinates?

7
  • 3
    In iOS the origin is top left, in macOS it's indeed bottom left. Commented Jul 30, 2021 at 6:20
  • I see. Either way, I am trying to use the coordinates to define the screenBounds of CGWindowListCreateImage in which (according to the documentation) the origin is the top-left corner. Commented Jul 30, 2021 at 6:25
  • Hint: mouseLocation. Commented Jul 30, 2021 at 7:18
  • According to the documentationNSEvent.mouseLocation is suppose to return the coordinates in "screen coordinates". But I'm still getting the coordinates with respect to bottom left as the origin. Commented Jul 30, 2021 at 8:28
  • 1
    I guess you may want isFlipped? It reverses the coordinate system of a view. Commented Jul 30, 2021 at 8:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.