Menu
  • HOME
  • TAGS

Best place to intercept Cmd-Key in NSDocument based app

cocoa,nsdocument,nswindowcontroller,nsevent,nsresponder

Yes, subclassing NSWindow is the way to do this if you need to get the keyboard event after everything up the responder chain refused to handle it. Here's how I did it in one of my projects: - (void)keyDown:(NSEvent*)event { SEL keyDownBool = @selector(keyDownBool:); if ([[self delegate] respondsToSelector:keyDownBool] && [[self...

Detect left and right mouse click on NSView

swift,nsview,nsevent

You trap the corresponding mouseDown events import Cocoa class MyView : NSView { override func mouseDown(theEvent : NSEvent) { println("left mouse") } override func rightMouseDown(theEvent : NSEvent) { println("right mouse") } } See NSResponder for more magic....

NSView regisstering events on first click of mouse (making the app active)

objective-c,osx,nsview,osx-yosemite,nsevent

Found the issue. I had a NSTexField on the subview that was capturing the first mouseDown event. Just overlooked it.

Swift: How can I update NSMenuItem while it is active (visible)?

swift,nsmenu,nsmenuitem,nsevent

You need to read the docu about NSRunLoop when your menu is displayed none of your threads will get control. Do you need to tell the OS you want to participate.

How to determine pressed modifier keys when a Cocoa app is started?

osx,cocoa,nsevent

Put this in applicationDidFinishLaunching: NSUInteger modifiers = ([NSEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask); if (modifiers == NSAlternateKeyMask) { // do your sutff here } ...

Getting [NSEvent mouseLocation] in view coordination system

osx,mousedown,nsevent

You should be using locationInWindow, not mouseLocation. The docs on locationInWindow show how to go from there: NSPoint event_location = [theEvent locationInWindow]; NSPoint local_point = [self convertPoint:event_location fromView:nil]; ...