Re: Determine current mouse cursor position
Re: Determine current mouse cursor position
- Subject: Re: Determine current mouse cursor position
- From: eveningnick eveningnick <email@hidden>
- Date: Sun, 31 Oct 2010 22:37:21 +0200
> If you want the *current* mouse location at the time you decide to display
> the window, use +[NSEvent mouseLocation] or -[NSWindow
> mouseLocationOutsideOfEventStream].
>
> However, it's more than possible that you should be using the mouse
> location *synchronized with the application's event stream*. AFAIK there's
> no way to do that directly, or 100% reliably. The best way I know of is to
> monitor the mouse location in every mouse event as your application
> processes it. In 10.6, you can use
> +[addLocalMonitorForEventsMatchingMask:handler:] to do this. In 10.5, you
> have to subclass NSApplication and override 'sendEvent:'. In both cases, you
> won't see any events consumed by modal event loops -- at least, those
> consumed in frameworks -- but it doesn't sound like this would matter for
> you.
>
> Why would you want to do the second (harder) thing? Consider what would
> happen, assuming for example that the window pops up where you right click,
> if the mouse is moving fast away from the window. If there's a slight delay
> between the click and the display of the window, the mouse might have
> already moved a long way from the click site before the window position is
> calculated.
>
Hi Quincey
Thank you for the answer. You were right, i don't want to get the mouse
location as a snapshot.
Basically what i need to do - is to monitor system-widely, because i need to
watch that mouse not only when the mouse is over my app's window, but even
if it is over the Dock. And to monitor those events even if my application
is not active at the moment. I guess sendEvent works only when the
application is active and when the mouse is on top of the window? (and, as i
remember, some flag should be set to allow mousemove events me dispatched)?
Thanks again, George
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden