Convert screen coordinate to window coordinate in Cocoa?

805 views Asked by At

I've seen this question asked multiple times here, and I tried some answers, but it doesn't seem to work for me.

NSPoint pnt = [[self window] convertScreenToBase:[NSEvent mouseLocation]];

I'm using above code to do my conversion, but I get same coordinates for pnt.x and pnt.y no matter where mouse location is.

I noticed that this method is deprecated, but it should still work I guess, right?

Does anyone have any good suggestion on how I can do this conversion?

Any kind of help is highly appreciated!

1

There are 1 answers

4
Ken Thomases On BEST ANSWER

You should use [window mouseLocationOutsideOfEventStream] instead.