Mouse events

Post: #1
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.

Quote this message in a reply
Posts: 104
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Post: #3
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.
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).
Quote this message in a reply
Post: #4
Thanks for the info guysSmile
Quote this message in a reply
Post: #5
Grin 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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Full screen mouse events Mister T 17 14,543 Jan 4, 2010 02:55 PM
Last Post: MacMan
  Mouse Events in NSView Chandhu 1 5,383 Feb 28, 2008 02:08 AM
Last Post: kuon_
  Mouse events for an openGL window majestik666 5 9,375 Jul 5, 2005 06:15 PM
Last Post: majestik666
  Accepting Mouse Moved Events geezusfreeek 6 6,324 Nov 16, 2002 06:34 PM
Last Post: geezusfreeek