Swift noob: just want the coordinates of the mouse

288 views
Skip to first unread message

matt martin

unread,
Apr 21, 2015, 4:28:16 PM4/21/15
to swift-l...@googlegroups.com
Hi 

I'm new to Swift, coming from some knowledge of Java. I'm working on an app that needs to do something any time the mouse is moved. VERY SIMPLE!!

I have searched and searched, and tried to understand how to use Objective-C things like NSMouseMoved or setup a NSTrackingArea, but find myself lost in the weeds without a CS education.

thanks!
Matt

Jens Alfke

unread,
Apr 21, 2015, 5:02:16 PM4/21/15
to matt martin, swift-l...@googlegroups.com

On Apr 21, 2015, at 1:28 PM, matt martin <johnmat...@gmail.com> wrote:

I'm new to Swift, coming from some knowledge of Java. I'm working on an app that needs to do something any time the mouse is moved. VERY SIMPLE!!

Welcome! But you’re asking a question about the Cocoa frameworks, not about the Swift language. The best place to ask for help with Cocoa is either the cocoa-dev mailing list or Apple’s developer forums.

(And BTW the reason this isn’t as simple as you’d think is that the OS wants to limit the number of events it sends the app — event handling consumes CPU and energy. So tracking areas are a way for the app to find out when the cursor position changes in a meaningful way without having to receive hundreds of events every time the mouse moves. It’s possible to get an event every time the mouse moves, but that takes a bit more work because few apps need to do it.)

—Jens

matt martin

unread,
Apr 21, 2015, 5:05:37 PM4/21/15
to swift-l...@googlegroups.com, johnmat...@gmail.com
Yes, I see your point. I guess I'm just surprised there is no simple get.mouseX and get.mouseY methods for us to use. I'm probably ditching this project now!

thanks for the reply.
Matt

matt martin

unread,
Apr 21, 2015, 6:13:15 PM4/21/15
to swift-l...@googlegroups.com, johnmat...@gmail.com

Jim Dovey

unread,
Apr 21, 2015, 6:58:13 PM4/21/15
to matt martin, swift-l...@googlegroups.com
That’s not “in Swift” either I’m afraid. It’s a method implemented by subclasses of NSResponder, which is part of Cocoa. You’re still better off asking the cocoa-dev mailing list about that one.

-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.
To post to this group, send email to swift-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/94c5b2b0-c4f7-42d6-a044-7eed10499bed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

matt martin

unread,
Apr 21, 2015, 7:16:26 PM4/21/15
to swift-l...@googlegroups.com, johnmat...@gmail.com

Sorry to bother you! I understand that what I was looking at was not "pure" Swift, but a Swift implementation

Adam Sharp

unread,
Apr 21, 2015, 7:29:19 PM4/21/15
to swift-l...@googlegroups.com
It's no problem! Hope you find what you're looking for soon.

> On 22 Apr 2015, at 9:16 am, matt martin <johnmat...@gmail.com> wrote:
>
> I understand that what I was looking at was not "pure" Swift, but a Swift implementation

Just to be clear, what you're seeing is not actually a Swift *implementation*, but the *interface* translated to Swift. NSResponder is part of Cocoa and is implemented in Objective-C, it just happens that the API is bridged to Swift, and thus the documentation is showing you the Swift translation of it.

I'm using the terms "translate" and "bridge" loosely, but I hope that clears things up for you a little.

–Adam
Reply all
Reply to author
Forward
0 new messages