Screen MousePosition Cocoa mouseLocation

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 605
Joined: Thu May 30, 2013 4:39 pm

Screen MousePosition Cocoa mouseLocation

Post by Wolfram »

Can some one show me how to use the cocoa mouseLocation command to get the mouse position on screen?
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Screen MousePosition Cocoa mouseLocation

Post 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) .
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 605
Joined: Thu May 30, 2013 4:39 pm

Re: Screen MousePosition Cocoa mouseLocation

Post 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" ?
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Screen MousePosition Cocoa mouseLocation

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Screen MousePosition Cocoa mouseLocation

Post by mestnyi »

Just take a look at the cocoa classes once in a while :wink:
where are these lessons?
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Screen MousePosition Cocoa mouseLocation

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply