views:

35

answers:

1

It used to be that in Carbon you could use SetMenuItemKeyGlyph. What's the alternative under 10.6? Will I need to use undocumented goodness or...?

Thanks

+1  A: 

Use -[NSMenuItem setKeyEquivalent:] and give it an NSString of the character you want to be used. NSMenuItem will handle translating @" " into Space for you, etc.

Delete key (aka "Backspace". This is the regular delete button on your keyboard):

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x08]];

Forward delete key (The "del" key):

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x7f]];

Space:

[myMenuItem setKeyEquivalent:@" "];

Tab:

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x09]];
Dave DeLong
Awesome, thanks! Would you know where I can pull up the codes for the eject, escape, and cursor arrow keys?Thanks
the979kid
Found them :) Menus.h has a helpful listing of glyph codes.
the979kid
Not all glyph codes in Menus.h will work since Cocoa bit shifts some of them, including the arrow keys. There are enums for these in Cocoa. NSUpArrowFunctionKey = 0xF700, NSDownArrowFunctionKey = 0xF701, NSLeftArrowFunctionKey = 0xF702, NSRightArrowFunctionKey = 0xF703
the979kid