I am trying to use improve a GTK# application which runs on Mac OS by using the API that MonoMac exposes and build a native Mac menu using the NSMenuItem and NSMenu classes.
So far everything looks good and I was able to set some keyboard accelerators (KeyEquivalent) to the menu but the problem is that they don't react to the keyboard. The key combinations are displayed correctly in the menu but pressing the keys do not do anything. Selecting the menu items using the mouse works fine.
Here is some code that I used to initialize the the environment:
NSApplication.InitDrawingBridge ();
NSApplication.Init ();
NSMenuItem super = new NSMenuItem (DataHelper.ProductName);
super.Submenu = new NSMenu (DataHelper.ProductName);
NSMenu mainMenu = new NSMenu ();
mainMenu.AddItem (super);
NSApplication.SharedApplication.MainMenu = mainMenu;
< menu initialization comes here >
NSApplication.SharedApplication.Delegate = new AppDelegate ();
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
Is there anything else I have to do in order to make the keyboard events pass to the menu?
I looked at MonoDevelop for code reference and could not find anything that could make that difference. I used some code from there for setting the KeyEquivalent values too.
It turns out that GTK does not automatically send the KeyPress events to the menu if they remain unhandled. What I did was to capture the event on the outermost container in GTK and manually send it to the Mac Menu like that: