简体   繁体   中英

Clicking menubar icon Cocoa

I am making an menubar application and now I want to create function that when you press ALT key and then click the statusbar icon of the app. It shows all the menus that are there, some are hidden because you can toggle it by yourself. I really would like to know how I could make something like

if ([theappinthestatusbar = clicked]) {
    [menuitem setHidden:NO];
} else {
    [menuitem setHidden:YES];
}

Any help or suggestions are greatly appreciated.

Implement the delegate method menuNeedsUpdate: of NSMenu and show/hide the menu item depending on the -Key

- (void)menuNeedsUpdate:(NSMenu *)aMenu
{
    NSUInteger flags = ([NSEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask);
    BOOL shouldHideSecretMenu = !(flags == NSAlternateKeyMask);
    [menuitem setHidden:shouldHideSecretMenu];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM