I work on a very keyboard intensive application. Both hands on the keyboard. No hands on the mouse.
A user can, via the keyboard, popup a context menu, select an item and finally hit enter.
[NSMenu popUpContextMenu]
displays the menu without highlighting any item. The user will have to press arrow_down one time in order to highlight the first item.
A friend of mine observed that you have to press arrow_down every time you use this menu and suggested that I removed this step, so that the first item is always highlighted when the menu is popuped.
I suspect it requires a carbon hack?
How can one programmatically highlight the first item?
I use this code to popup a menu.
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined
location:location
modifierFlags:0
timestamp:0
windowNumber:[[self window] windowNumber]
context:[[self window] graphicsContext]
subtype:100
data1:0
data2:0
];
[NSMenu popUpContextMenu:menu withEvent:event forView:self];
update: I have tried sending my app an arrow_down event right after the popUpContextMenu, however the event isn't executed when the menu is visible. (The event is executed after the menu is gone).
unichar code = NSDownArrowFunctionKey;
NSString* chars = [NSString stringWithFormat: @"%C", code];
NSEvent* event = [NSEvent keyEventWithType:NSKeyDown location:location modifierFlags:0 timestamp:0 windowNumber:[[self window] windowNumber] context:[[self window] graphicsContext] characters:chars charactersIgnoringModifiers:chars isARepeat:NO keyCode:code];
[NSApp sendEvent:event];