R – Disabling ESC and Command . in an OSX Cocoa app

cocoaikpicturetakermacosobjective c

I made a little cocoa app that brings up an IKPictureTaker and saves a picture to a file if you press the set button. Currently, if you press esc or Command . the window picture taker will close. Is there a way to disable this behavior?

Best Answer

Another approach is to hide the close and Cancel buttons, so they can't be pressed:

IKPictureTaker *taker = [IKPictureTaker pictureTaker];
[taker setStyleMask:0]; //disable close button
for(NSView *aView in [[taker contentView] subviews]){
 if([aView isKindOfClass:[NSButton class]]){
  NSButton *aButton = (NSButton*)aView;
  if([aButton action] ==  @selector(cancelButton:))
   [aButton setHidden:YES];
 }
}