3

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?

Jordan Kay
  • 368
  • 3
  • 14

3 Answers3

1

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.

omz
  • 53,243
  • 5
  • 129
  • 141
1

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.

danielpunkass
  • 17,527
  • 4
  • 24
  • 38
  • Interesting. Turns out the key equivalent works for some menu items, but not others. What are "special" menu items? – Jordan Kay Aug 01 '11 at 21:56
  • Updated answer to explain a bit more about my hunch. – danielpunkass Aug 01 '11 at 22:04
  • Yep, I tried using that as well, and the same problem occurs. There seems to be no rhyme or reason to which ones it will allow and which ones it won't. – Jordan Kay Aug 01 '11 at 22:07
  • You mean, it fails on some "completely innocuous" menu items? Like one that you just add to the bottom of your File menu, say? If it only fails on system-standardish menu items, then at least that is some rhyme :) – danielpunkass Aug 01 '11 at 22:11
  • It fails only a complete app-specific menu item added to a completely app-specific menu in the menu bar. Nothing system wide. When I add it to the File menu, interestingly enough, it works. – Jordan Kay Aug 01 '11 at 22:13
  • Inclined to suspect something in your app is doing monkey business with your completely app-specific menu items :) – danielpunkass Aug 01 '11 at 22:15
  • Very strange. Command-Option-C and Command-Control C fail; Option-C and Shift-Option-C work. Like I said, no rhyme or reason. – Jordan Kay Aug 01 '11 at 22:26
  • @danielpunkass let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2038/discussion-between-jordan-kay-and-danielpunkass) – Jordan Kay Aug 01 '11 at 23:23
0
  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
Martin Pilkington
  • 3,261
  • 22
  • 16