Swift noob: just want the coordinates of the mouse

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Swift noob: just want the coordinates of the mouse

matt martin
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/b6745298-7a91-46c3-8558-75b701e1eee3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

Jens Alfke

On Apr 21, 2015, at 1:28 PM, matt martin <[hidden email]> 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/72CAB0F4-86CD-4B12-8A18-9CBDDF3CBC27%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

matt martin
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



On Tuesday, April 21, 2015 at 5:02:16 PM UTC-4, Jens Alfke wrote:

On Apr 21, 2015, at 1:28 PM, matt martin <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="DZ2uqAKFJZoJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">johnmat...@...> 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 <a href="https://lists.apple.com/mailman/listinfo/cocoa-dev" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;">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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/ba6272f0-25bb-4af6-be6b-49bde61693a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

matt martin
But wait, there is a mouseMoved function in Swift. How do I utilize this?

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/index.html#//apple_ref/doc/uid/20000015-SW2


On Tuesday, April 21, 2015 at 5:05:37 PM UTC-4, matt martin wrote:
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



On Tuesday, April 21, 2015 at 5:02:16 PM UTC-4, Jens Alfke wrote:

On Apr 21, 2015, at 1:28 PM, matt martin <[hidden email]> 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 <a href="https://lists.apple.com/mailman/listinfo/cocoa-dev" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;">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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

Jim Dovey
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.

On Apr 21, 2015, at 3:13 PM, matt martin <[hidden email]> wrote:

But wait, there is a mouseMoved function in Swift. How do I utilize this?



On Tuesday, April 21, 2015 at 5:05:37 PM UTC-4, matt martin wrote:
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



On Tuesday, April 21, 2015 at 5:02:16 PM UTC-4, Jens Alfke wrote:

On Apr 21, 2015, at 1:28 PM, matt martin <[hidden email]> 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

-- 
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/DD79CF49-7926-4D3D-B055-BEA0B739C638%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

matt martin

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

On Tuesday, April 21, 2015 at 6:58:13 PM UTC-4, Jim Dovey wrote:
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.

On Apr 21, 2015, at 3:13 PM, matt martin <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ps1SsAthBcIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">johnmat...@...> wrote:

But wait, there is a mouseMoved function in Swift. How do I utilize this?

<a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/index.html#//apple_ref/doc/uid/20000015-SW2" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2Fdocumentation%2FCocoa%2FReference%2FApplicationKit%2FClasses%2FNSResponder_Class%2Findex.html%23%2F%2Fapple_ref%2Fdoc%2Fuid%2F20000015-SW2\46sa\75D\46sntz\0751\46usg\75AFQjCNE-0XTsOJ_S2o6Py8VvNojTU3FhCA';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2Fdocumentation%2FCocoa%2FReference%2FApplicationKit%2FClasses%2FNSResponder_Class%2Findex.html%23%2F%2Fapple_ref%2Fdoc%2Fuid%2F20000015-SW2\46sa\75D\46sntz\0751\46usg\75AFQjCNE-0XTsOJ_S2o6Py8VvNojTU3FhCA';return true;">https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/index.html#//apple_ref/doc/uid/20000015-SW2


On Tuesday, April 21, 2015 at 5:05:37 PM UTC-4, matt martin wrote:
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



On Tuesday, April 21, 2015 at 5:02:16 PM UTC-4, Jens Alfke wrote:

On Apr 21, 2015, at 1:28 PM, matt martin <[hidden email]> 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 <a href="https://lists.apple.com/mailman/listinfo/cocoa-dev" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Flists.apple.com%2Fmailman%2Flistinfo%2Fcocoa-dev\46sa\75D\46sntz\0751\46usg\75AFQjCNE0l9jtHXOW-AdVxf_H9uqpvhdKGg';return true;">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

-- 
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 <a href="javascript:" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" gdf-obfuscated-mailto="ps1SsAthBcIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-languag...@googlegroups.com.
To post to this group, send email to <a href="javascript:" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" gdf-obfuscated-mailto="ps1SsAthBcIJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-l...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/swift-language/94c5b2b0-c4f7-42d6-a044-7eed10499bed%40googlegroups.com?utm_medium=email&amp;utm_source=footer" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/swift-language/94c5b2b0-c4f7-42d6-a044-7eed10499bed%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/swift-language/94c5b2b0-c4f7-42d6-a044-7eed10499bed%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/swift-language/94c5b2b0-c4f7-42d6-a044-7eed10499bed%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/d8bdfa9f-cd71-4623-b110-9bede7072fbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Swift noob: just want the coordinates of the mouse

Adam Sharp
It's no problem! Hope you find what you're looking for soon.

> On 22 Apr 2015, at 9:16 am, matt martin <[hidden email]> 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/15B24FF8-4780-4139-8E24-2221F2235135%40me.com.
For more options, visit https://groups.google.com/d/optout.