Page 1 of 1

Screen MousePosition Cocoa mouseLocation

Posted: Wed Feb 11, 2015 5:45 pm
by Wolfram
Can some one show me how to use the cocoa mouseLocation command to get the mouse position on screen?

Re: Screen MousePosition Cocoa mouseLocation

Posted: Wed Feb 11, 2015 6:39 pm
by wilbert

Code: Select all

Location.NSPoint
CocoaMessage(@Location, 0, "NSEvent mouseLocation")

Debug Location\x
Debug Location\y
Be aware that on OS X, not the top left but the bottom left location is (0, 0) .

Re: Screen MousePosition Cocoa mouseLocation

Posted: Wed Feb 11, 2015 7:34 pm
by Wolfram
wilbert wrote:

Code: Select all

Location.NSPoint
CocoaMessage(@Location, 0, "NSEvent mouseLocation")

Debug Location\x
Debug Location\y
Be aware that on OS X, not the top left but the bottom left location is (0, 0) .
Thanks Wilbert!

But how do I know that class func mouseLocation() -> NSPoint musst be written as "NSEvent mouseLocation" ?

Re: Screen MousePosition Cocoa mouseLocation

Posted: Wed Feb 11, 2015 10:04 pm
by wilbert
Wolfram wrote:how do I know that class func mouseLocation() -> NSPoint musst be written as "NSEvent mouseLocation" ?
Just take a look at the cocoa classes once in a while :wink: That's how I knew.
If you look at the NSEvent Class Reference you see it marked with a (+) indicating that it's a class function that doesn't require to create an instance first.
A lot of other methods are instance methods marked with a (-) that need a class instance to work on.

Re: Screen MousePosition Cocoa mouseLocation

Posted: Sun Nov 06, 2022 4:48 am
by mestnyi
Just take a look at the cocoa classes once in a while :wink:
where are these lessons?

Re: Screen MousePosition Cocoa mouseLocation

Posted: Sun Nov 06, 2022 11:39 am
by mk-soft
What mean with [+] [-] ?
Link: https://developer.apple.com/documentati ... guage=objc

If I don't know which methods there are or the description is not quite right, I display the methods of an object.
Link: Dump Object Methods