I have an NSTextField which uses as an extended NSTextFieldCell, which creates a custom field editor, that intercepts and records key events. (Knowing the key events is impo
This is just the way the event architecture is set up. Sending key equivalent messages is preferred to sending messages for the various keys that are part of them. See "Handling Key Events," in particular, "Handling Key Equivalents." It looks like you could subclass NSApplication
and override -sendEvent:
to dispatch these events however you'd like, but you'd likely break more functionality than you'd add.
For others, this is the code to "fix" it:
- (void)sendEvent:(NSEvent *)event {
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
[[self keyWindow] sendEvent:event];
else
[super sendEvent:event];
}
To keep the normal application behavior and add your own (minimising the chances of unanticipated side effects), notifications are are a possibility:
- (void)sendEvent:(NSEvent *)theEvent
{
[super sendEvent:theEvent];
if (theEvent.modifierFlags & NSCommandKeyMask) {
if (theEvent.type == NSKeyUp) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"myKeyUp" object:theEvent];
}
if (theEvent.type == NSKeyDown) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"myKeyDown" object:theEvent];
}
}
}
Then add an the appropriate object(s) as observer(s) for the notifications.