Cocoa – continue tracking mouse-drag event even after cursor moves out of the movie

cocoa

I have few views aligned in grids in parent view (All being NSView's )

I am overriding
-(void)mouseDown:(NSEvent *)event
– (void)mouseDragged:(NSEvent *)theEvent for some custom drawing in child view subclass

To be specific, I draw some rectangle boxes during mouse drag in child view's.

Problem: when cursor moves out of the child view( during mouse drag ) , obviously, I am not able to track the event and hence I cannot resize the rectangle.
I want to track the mouse movements even outside the application window… (for now just the drag event )

Is there any obvious or complex way to achieve this…..

Thanks in Advance

Rajesh

Best Answer

- (void)mouseDown:(NSEvent *)theEvent
{
    NSPoint point;
    while (1) {
        theEvent = [[self window] nextEventMatchingMask: (NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
        point = [self convertPoint: [theEvent locationInWindow] fromView: nil];

        // do something with point

        if ([theEvent type] == NSLeftMouseUp)
            break;
    }
}
Related Topic