Ronald Hofmann
Ronald Hofmann

Reputation: 1430

Objective-C Why do some mouse events fire and others don´t

my View controller works fine so far except one thing: I have a couple of MouseEvents and some fire and others don´t.

- (void)mouseWasHeld: (NSTimer *)tim {
    **// this works not**
}

- (void) mouseMoved:(NSEvent*)someEvent {
    **// this works not**
}

-(void)mouseDown:(NSEvent *)event {
    // this works
}

-(void)mouseDragged:(NSEvent *)event {
    // this works
}

-(void)mouseUp:(NSEvent *)event {
// this works
}

I don´t see why two events don´t fire any clues?

Thanks a lot Ronald

Upvotes: 1

Views: 228

Answers (2)

Ramaraj T
Ramaraj T

Reputation: 5230

mouseMoved: will not be called unless you add the Tracking area.

 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
 NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:self.frame options:options owner:self userInfo:nil];
 [self addTrackingArea:trackingArea];

Upvotes: 1

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

  1. mouseWasHeld: seems to be a callback of a timer setup anywhere else. Look for @selector(mouseWasHeld:) in your code and find out why the timer is not scheduled.
  2. mouseMoved: is only dispatched if the window is told to do so using -[NSWindow setAcceptsMouseMovedEvents:].

Upvotes: 2

Related Questions