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];
}
}
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 handlingmouseUp:
instead ofmouseDown:
, 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:
ororderOut:
action.