Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8493025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:53:36+00:00 2026-06-10T22:53:36+00:00

I want to add a menu item into the application’s main menu that will

  • 0

I want to add a menu item into the application’s main menu that will be used quite rare. I want it to be hidden by default and show it only when user hold down Option key. How do i do this?

It seems that I should handle flagsChanged:, but it is NSResponder‘s method and NSMenu does not inherits from NSResponder? I tried it inside main window controller, and it works when I press Option key before I click on menu. The following use case doe not work: click on menu item (there is no item), press option key — my item should appear, release option key — item should disappear.

I’ve also tried NSEvent’s addLocalMonitorForEventsMatchingMask:handler: and addGlobalMonitorForEventsMatchingMask:handler: for NSFlagsChangedMask but when option key pressed while main menu is open neither local or global handlers are not fired.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:53:38+00:00Added an answer on June 10, 2026 at 10:53 pm

    Add the following to applicationDidFinishLaunching.

    // Dynamically update QCServer menu when option key is pressed
    NSMenu *submenu = [[[NSApp mainMenu] itemWithTitle:@"QCServer"] submenu];    
    NSTimer *t = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateMenu:) userInfo:submenu repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:t forMode:NSEventTrackingRunLoopMode];
    

    then add

    - (void)updateMenu:(NSTimer *)t {
    
        static NSMenuItem *menuItem = nil;
        static BOOL isShowing = YES;
    
        // Get global modifier key flag, [[NSApp currentEvent] modifierFlags] doesn't update while menus are down
        CGEventRef event = CGEventCreate (NULL);
        CGEventFlags flags = CGEventGetFlags (event);
        BOOL optionKeyIsPressed = (flags & kCGEventFlagMaskAlternate) == kCGEventFlagMaskAlternate;
        CFRelease(event);
    
        NSMenu *menu = [t userInfo];
    
        if (!menuItem) {
            // View Batch Jobs...
             menuItem = [menu itemAtIndex:6];
            [menuItem retain];
        }
    
        if (!isShowing && optionKeyIsPressed) {
            [menu insertItem:menuItem atIndex:6];
            [menuItem setEnabled:YES];
            isShowing = YES;
        } else if (isShowing && !optionKeyIsPressed) {
            [menu removeItem:menuItem];
            isShowing = NO;
        }
    
        NSLog(@"optionKeyIsPressed %d", optionKeyIsPressed);
    }
    

    The timer only fires while controls are being tracked so it’s not too much of a performance hit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Next to file menu i want to add a search menu that will have
I want to add submenu into the main menu in runtime. I have looked
I have a menu item to which I add another item. Now I want
I want to hide the Admin Panel menu item from visitor, without going into
is there a possibility that i should be able to add some menu item
i want to add a button or menu item in the Contacts menu .
I want to add a Menu Item Type for my component. Have a look
I want to add a menu item for the OS X Dock Trash icon.
I want to add menu at footer in Drupal. (e.g. contact us | sitemap
I have a one master Page. I want to add 3 Menu items to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.