Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Mouse Tracking in an NSView

Mouse Tracking in an NSView
Thread Tools
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 5, 2001, 01:33 PM
 
quick question,
right now I have an app that can track the mouse when it is dragged, I just use
- (void)mouseDragged NSEvent *)event {
But when I want to track it when I simply move the mouse around, I change Dragged to Moved and then nothing happens...

How can I track mouse movements?

Thanks
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
May 5, 2001, 07:18 PM
 
By default, windows do not track mouse moved events. Use the NSWindow method -setAcceptsMouseMovedEvents: to change this.

Depending on what you're trying to do, tracking rects or cursor rects might be a better way to do (a bit harder to program though). See the "Mouse Events" and "Tracking Rectangles and Cursor Rectangles" sections in the NSView class documentation for more info.
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 6, 2001, 07:16 PM
 
how exactly would i do that... im kind of new...
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
May 7, 2001, 06:26 PM
 
If you have an outlet to the window, call [theWindow setAcceptsMouseMovedEvents:YES]; after loading the nib. If this is in the main nib, you can do it in applicationDidFinishLaunching. If this controlled by an NSDocument subclass, do it in -windowControllerDidLoad:.

Alternatively, you could implement -awakeFromNib in your view class:

-(void)awakeFromNib
{
[[self window] setAcceptsMouseMovedEvents:YES];
}

     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
May 7, 2001, 09:30 PM
 
sweet, thanks!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2