0

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!

Eugene Gordin
  • 4,047
  • 3
  • 47
  • 80

1 Answers1

3

You should use [window mouseLocationOutsideOfEventStream] instead.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • 3
    Try providing some more information on what that does that makes it a better candidate to resolve the problem. – Brandon Buck Aug 15 '14 at 10:08
  • I think it would be more helpful for the OP and further visitors, when you add some explanation to your intension. – Reporter Aug 15 '14 at 10:29
  • @BrandonBuck: The method does precisely what the question was trying to do. It returns the mouse location in the coordinates of a window rather than the screen ("converted" as it were). I'm having a hard time imagining what more can be said. Also, the questioner already indicated in the comments that it solved their problem. – Ken Thomases Aug 15 '14 at 11:55
  • 1
    Bam, "`[window mouseLocationOutsideOfEventStream]` will return the mouse coordinates in the context of the window instead of the screen like you're looking for. Here's a very short example of how you'd employ this method ...". I'll be honest, when I get SO questions as search results, the first thing I do is look at answers and answers like this mean nothing to me because it's just a method call. While you are answering the question asked, you also have to think about who else might see this page - you're answering their questions as well. – Brandon Buck Aug 15 '14 at 15:41