Mouse events
I would like to know how to track the mouse using cocoa.
I have been useing glut and c and using the mouse tracking functions from that.
But i would like to know how to do this in cocoa.
thanks.
I have been useing glut and c and using the mouse tracking functions from that.
But i would like to know how to do this in cocoa.
thanks.
Check out NSEvent.h in the appkit headers. Also, you'll need to set up your window to accept mouseMoved events. The ZedNought source code has some examples of this.
First as GoodDoug has said, you must setup your window to accept mouse moved events.
[myNSWindow setAcceptsMouseMovedEvents: YES];
Then you retrieve your events in a standard event loop using
[NSApp nextEventMatchingMask: untilDate: inMode: dequeue:]
Then you check for the event type (there are probably other types of events you want to check for in there). If it is equal to either NSMouseMoved, NSLeftMouseDragged, NSRightMouseDragged and 27 (Undocumented other mouse event), you can retrieve the mouse info from teh event as well. If you need relative movement, you could call coregraphics function in there
CGGetLastMouseDelta(&deltaX, &deltaY);
most of this stuff is in NSEvent.h and it is indeed a good ideayou check it out. There is probably a topic in the documentation about this as well. You can also have a look at omni's GDC demo code for catching events in cocoa.
http://www.omnigroup.com/developer/gamed...t/gdc2001/
I haven't checked ZedNought's code yet but it's most likely a good place to look for examples.
Ah, one last point, you might also want to disable mouse filtering (or mouse scaling).
[myNSWindow setAcceptsMouseMovedEvents: YES];
Then you retrieve your events in a standard event loop using
[NSApp nextEventMatchingMask: untilDate: inMode: dequeue:]
Then you check for the event type (there are probably other types of events you want to check for in there). If it is equal to either NSMouseMoved, NSLeftMouseDragged, NSRightMouseDragged and 27 (Undocumented other mouse event), you can retrieve the mouse info from teh event as well. If you need relative movement, you could call coregraphics function in there
CGGetLastMouseDelta(&deltaX, &deltaY);
most of this stuff is in NSEvent.h and it is indeed a good ideayou check it out. There is probably a topic in the documentation about this as well. You can also have a look at omni's GDC demo code for catching events in cocoa.
http://www.omnigroup.com/developer/gamed...t/gdc2001/
I haven't checked ZedNought's code yet but it's most likely a good place to look for examples.
Ah, one last point, you might also want to disable mouse filtering (or mouse scaling).
I (just yesterday) posted a thread called Cursor in Cocoa and I got an good answer. The source code I made uses mouse moved events because CGGetLastMouseDelta(&deltaX, &deltaY) didnt work, anyway I will upload the source code and you can check the thread for an example of mouse moved event tracking.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Full screen mouse events | Mister T | 17 | 7,486 |
Jan 4, 2010 02:55 PM Last Post: MacMan |
|
| Mouse Events in NSView | Chandhu | 1 | 3,532 |
Feb 28, 2008 02:08 AM Last Post: kuon_ |
|
| Mouse events for an openGL window | majestik666 | 5 | 6,809 |
Jul 5, 2005 06:15 PM Last Post: majestik666 |
|
| Accepting Mouse Moved Events | geezusfreeek | 6 | 3,864 |
Nov 16, 2002 06:34 PM Last Post: geezusfreeek |
|

