I realize this question is really old, but I was just working on this, so... The below approach works for me.
- (void)keyDown:(NSEvent *)theEvent
{
NSString* replacementKey = nil;
switch ([theEvent keyCode])
{
case 123: // Left arrow
replacementKey = @"-";
break;
case 124: // Right arrow
replacementKey = @"+";
break;
case 125: // Down arrow
replacementKey = @"]";
break;
case 126: // Up arrow
replacementKey = @"[";
break;
case 53: // esc
case 36: // return -- don't assign replacement key and these will dismiss date picker
break;
default:
replacementKey = [theEvent charactersIgnoringModifiers];
break;
}
if (replacementKey) // 'letter' based shortcut keys
{
[self.textFieldCell dateShortcut:replacementKey];
[self updateGraphicalCalendar];
}
else
{
[self.textFieldCell hidegraphicCalendar];
}
}
Note this is for a graphical date picker associated with a custom NSTextFieldCell. The custom textfieldcell handles the shortcut keys (the "replacementKey") by modifying the selected date, like:
if (NSOrderedSame == [shortcut caseInsensitiveCompare:@"+"] || NSOrderedSame == [shortcut caseInsensitiveCompare:@"="]) // '=' is unshifted '+'
{
emptyComponents.day = 1;
currentDateValue = [calendar dateByAddingComponents:emptyComponents toDate:currentDateValue options:0];
}
else if (NSOrderedSame == [shortcut caseInsensitiveCompare:@"-"])
{
emptyComponents.day = -1;
currentDateValue = [calendar dateByAddingComponents:emptyComponents toDate:currentDateValue options:0];
}
else if (NSOrderedSame == [shortcut caseInsensitiveCompare:@"["]) // same day in previous week
{
emptyComponents.day = -7;
currentDateValue = [calendar dateByAddingComponents:emptyComponents toDate:currentDateValue options:0];
}
else if (NSOrderedSame == [shortcut caseInsensitiveCompare:@"]"]) // same day in next week
{
emptyComponents.day = 7;
currentDateValue = [calendar dateByAddingComponents:emptyComponents toDate:currentDateValue options:0];
}