keyUp event heard?: Overridden NSView method

Posted by Old McStopher on Stack Overflow See other posts from Stack Overflow or by Old McStopher
Published on 2009-12-06T02:03:10Z Indexed on 2011/01/11 8:53 UTC
Read the original article Hit count: 260

UPDATED: I'm now overriding the NSView keyUp method from a NSView subclass set to first responder like below, but am still not seeing evidence that it is being called.

@implementation svsView

- (BOOL)acceptsFirstResponder {
    return YES;
}

- (void)keyUp:(NSEvent *)event {
  //--do key up stuff--
  NSLog(@"key up'd!");
}

@end

--ORIGINAL POST-- I'm new to Cocoa and Obj-C and am trying to do a (void)keyUp: from within the implementation of my controller class (which itself is of type NSController). I'm not sure if this is the right place to put it, though. I have a series of like buttons each set to a unique key equivalent (IB button attribute) and each calls my (IBAction)keyInput method which then passes the identity of each key onto another object. This runs just fine, but I also want to track when each key is released.

--ORIGINAL [bad] EXAMPLE--

@implementation svsController

//init
//IBActions

- (IBAction)keyInput:(id)sender {
  //--do key down stuff--
}

- (void)keyUp:(NSEvent *)event {
  //--do key up stuff--
}

@end

Upon fail, I also tried the keyUp as an IBAction (instead of void), like the user-defined keyInput is, and hooked it up to the appropriate buttons in Interface Builder, but then keyUp was only called when the keys were down and not when released. (Which I kind of figured would happen.)

Pardon my noobery, but should I be putting this method in another class or doing something differently? Wherever it is, though, I need it be able to access objects owned by the controller class.

Thanks for any insight you may have.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa