Re: howto get global mouse states
Re: howto get global mouse states
- Subject: Re: howto get global mouse states
- From: Henry McGilton <email@hidden>
- Date: Tue, 5 Oct 2004 06:29:16 -0700
On Monday, October 4, 2004, at 09:58 AM, Sean McBride wrote:
Christian Robl (email@hidden) on Mon, Oct 4, 2004 06:34 said:
I want to build a COCOA application wich should recenter its window
on the
current mouseposition if a particular mouse button is pressed (e.g.
middle
button).
First, I have to say that's a pretty weird thing to do, but I'll give
you
the benefit of the doubt that you know what you're doing. :)
Actually, two of my apps are designed to position their 'origin' at the
current mouse position when the user types command-O.
In "awakefromnib" I call [NSEvent mouseLocation] for an initial window
placement which works great. While running the app I can get some
informations via polling [NSApp currentEvent] and
processign according the Event occured, but as soon as I mov/click
outside
of the app's window
no event occurs or is processed by my app.
Whats wrong?
I guess that's by design. If a click does not touch any interface
element of your application, then the OS sends the event elsewhere
(perhaps to another app's window that is underneath where you clicked).
How can I get mouse states regardless if the apps window is
clicked/active.
I don't know. Perhaps you could make a big invisible window that
covers
the screen(s) and is below all your other windows. Then, presumably,
that window would get events. I've never tried though.
That is essentially how I did it. There are two separate cases you need
to consider.
One case is when your application is the active application. You make
sure that
the mega-window/view responds to mouse moved events. Then you track the
mouse position all over the screen.
The other case is when your application is not the active application.
You have to watch for your application becoming active or inactive.
When it is the inactive application, you have to track the mouse via
a timer that fires off some trackMouse method call to obtain the
current mouse coordinates. Also make sure you watch for application
hide and unhide events, as you likely do not want the mouse tracking
to be done while the application is hidden.
You might want to experiment as to whether you in fact need a
huge window. MMy recollection is that my sole reason for doing
so was to be able to track cursor rects all over the screen.
Cheers,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
|
===============================+============================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden