View Full Version : Mouse events
madmax
2002.08.08, 06:59 PM
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.:)
GoodDoug
2002.08.09, 01:18 AM
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.
ylaporte
2002.08.09, 07:33 AM
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/gamedevelopment/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).
madmax
2002.08.09, 11:40 AM
Thanks for the info guys:)
ededed
2002.08.09, 02:44 PM
:D 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.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.