Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
i need a way to determine when a mouse moves over a certain area of my view, or its respective window - either is fine.

currently i used kEventControlTrack in conjunction with TrackMouseLocation to capture click and drag events, but this obviously won't work for just the mouse movement itself.
 
ok, i got it working - for some reason i had to install a separate handler for the mouse events from the custom view events... weird

i used these events to get it to work:

EventTypeSpec mouse_events[] = {
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassMouse, kEventMouseUp }
};

maybe it was because these events are exclusive to windows? i passed the view reference to the installer and it didn't work, but then passed a window ref and it did.
 
I did this recently using NSTrackingArea. You pass it an NSRect in your view co-ordinates and it gives you callbacks when the mouse enters or exits or moves within it. It is a 10.5 API though.
 
maybe it was because these events are exclusive to windows? i passed the view reference to the installer and it didn't work, but then passed a window ref and it did.

Just guessing, but it could be separate because mouse move events are so frequent and it doesn't want to send them unless necessary. It's kind of like this in Cocoa - you have to enable mouse move events at the window level to see them in a view.

I did this recently using NSTrackingArea. You pass it an NSRect in your view co-ordinates and it gives you callbacks when the mouse enters or exits or moves within it. It is a 10.5 API though.

He's using Carbon ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.