NSEvent - NSLeftMouseDown

1.5k views Asked by At

I'm trying to trigger basic functions using NSEvent and mouse clicks. For example close the window when pressing left mouse button. What else do I need in this method?

Thanks.

 - (void)mouseDown:(NSEvent *)theEvent {

if ([theEvent type] == NSLeftMouseDown){

    [window orderOut:nil];

  }
}
1

There are 1 answers

0
Peter Hosey On BEST ANSWER

Assuming this is in a custom view and the window outlet is connected (or you fill in that variable with [self window] when the view is added to a superview), that should be all you need. I would suggest handling mouseUp: instead of mouseDown:, though, to give the user the opportunity to back out by moving the mouse outside of your view.

You might also consider using an NSButton instead of (or inside of) a custom view. You could hook it up directly to the window's performClose: or orderOut: action.