For example, I have an NSMenuItem
type variable whose title is "History". I need a keyboard shortcut Meta+h to do the same thing as to click this menu item (pop up a submenu list)..
I think there might be two ways to implement this:
1.bind this menu item to a keyboard shortcut, then the Cocoa will fire the execute the action belongs to the item when the shortcut is fired
2.not binding keyboard shortcut to the item. Create an EventHandler for Meta+h, when the event activated, simulate a mouse click on the menu item.
However, both methods don't work for now.
For the keyboard shortcut, there is a method called setKeyEquivalent
, but it uses Command instead of Meta as the modifier. And its result is executing the action binds to the menu item, instead of poping up a submenu.
For the simulating of mouse click, in Cocoa's NSMenuItem
reference, I haven't see how to send event like click
to a NSMenuItem
..
Does anyone have ideas about this? Thanks!