I want to add a menu item to the main menu of the application, which will be used quite rarely. I want it to be hidden by default and only show when the user holds the Option key. How to do it?
It seems that I should handle flagsChanged:
but is this an NSResponder
method and NSMenu
not inheriting from NSResponder
? I tried it in the main window controller, and it works when I press the Option key before clicking on the menu. The following usage example does not work: click on a menu item (no item), press the select key - my item will appear, release the option key - the item should disappear.
I also tried NSEvent addLocalMonitorForEventsMatchingMask:handler:
and addGlobalMonitorForEventsMatchingMask:handler:
for NSFlagsChangedMask
, but when the select key is pressed when the main menu is open, neither local nor global handlers start.
How can i do this?
source share