Jordan Kay
Jordan Kay

Reputation: 368

Certain key equivalents cannot be used for NSMenuItem

I have an NSMenuItem for which I would like to use the key equivalent Command-Option-C. However, when I set the key equivalent in IB, it does not get associated with the menu item when the app is actually run. The entry has no visible key equivalent, and that command does not invoke the item. Other key equivalents, like Shift-Control-C, do indeed work. The one I am trying to use does not conflict with any other key equivalent in the app.

What could be causing this seemingly random problem?

Upvotes: 3

Views: 1480

Answers (3)

  1. Check the tag on your menu item. If set to certain values it might Cocoa to override stuff
  2. Check your system Prefs aren't overriding key bindings
  3. Check the key binding doesn't already exist elsewhere in the menu hierarchy, especially in the edit menu

Upvotes: 0

danielpunkass
danielpunkass

Reputation: 17587

Is it possible the menu item in question is a "special" menu item which may be getting substituted at launch-time by the system? If so, it would be helpful to know whether you are able to set the same keyboard shortcut on a different, perhaps less interesting menu item.

I don't really have an authoritative understanding of which menu items may get this kind of treatment, but have a suspicion for example that maybe the "Help" menu, "Application" menu, or others that are common across many apps get tweaked or even regenerated dynamically, altering what you specified in the nib.

The easiest workaround I would shoot for first is to call setKeyEquvialent: directly on the menu time from code, after the nib has loaded. I couldn't tell from your Twitter summary if you had already tried this, and it also failed.

Upvotes: 1

omz
omz

Reputation: 53551

Command-Option-C works just fine here. Could it be that you have a custom keyboard shortcut set up in the keyboard system preferences that uses the same key combination? That would override the application's own shortcuts.

Upvotes: 1

Related Questions