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 3624256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:29:07+00:00 2026-05-18T23:29:07+00:00

I am a .Net developer who need to port a small project into Mac,

  • 0

I am a .Net developer who need to port a small project into Mac, so I know next to nothing about Objective C. In fact the code below was just a bunch of grasping at straws and shooting in the dark.

Trying to build a Status Menu program that opens one or another window depending on if it is a left-click or a right-click/ctrl+click. Here is what I have, and it works for left-click only (obviously):

-(void) awakeFromNib{

    NSBundle *bundle = [NSbundle mainBundle];

    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
    [statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
    [statusItem setImage:statusImage];
    [statusItem setToolTip:@"Program Name"];
    [statusItem setHighlightMode:YES];
    [statusItem setAction:@selector(openWin:)];
    [statusItem setTarget: self];
}

-(void)openWin:(id)sender{
    [self openLeftWindow:sender];
}

-(IBAction)openLeftWindow:(id)sender{
    //Code to populate Left Click Window
    [leftWindow makeKeyAndorderFront:nil];
}

-(IBAction)openRightWindow:(id)sender{
    //Code to populate Right Click Window
    [rightWindow makeKeyAndorderFront:nil];
}

It seems to me that the solution would be either an if statement in the openWin() function to determine which button is clicked (or if ctrl was held down) then run the appropriate code or to make the menu aware of both the left and right clicks. But neither of these have worked when I attempted to do so.

Thanks In Advance.

  • 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-05-18T23:29:07+00:00Added an answer on May 18, 2026 at 11:29 pm

    If you will be satisfied with detecting control-click and not right click, then the first block of code will do what you want. If you really need the right click detection, you will have to use a custom view instead of an image in your NSStatusItem, and the second block of code will work.

    Simple Method:

    - (void)openWin:(id)sender {
        NSEvent *event = [NSApp currentEvent];
        if([event modifierFlags] & NSControlKeyMask) {
            [self openRightWindow:nil];
        } else {
            [self openLeftWindow:nil];
        }
    }
    

    Custom view method:

    - (void)awakeFromNib {
        ...
        statusImage = ...
        MyView *view = [MyView new];
        view.image = statusImage;
        [statusItem setView:view];
        [statusItem setToolTip:@"Program Name"];
        view target = self;
        view action = @selector(openLeftWindow:);
        view rightAction = @selector(openRightWindow:);
        [view release];
        //[statusImage release]; //If you are not using it anymore, you should release it.
    }
    
    MyView.h
    
    #import <Cocoa/Cocoa.h>
    @interface MyView : NSControl {
        NSImage *image;
        id target;
        SEL action, rightAction;
    }
    @property (retain) NSImage *image;
    @property (assign) id target;
    @property (assign) SEL action, rightAction;
    @end
    
    MyView.m
    
    #import "MyView.h"
    @implementation MyView
    @synthesize image, target, action, rightAction;
    - (void)mouseUp:(NSEvent *)event {
        if([event modifierFlags] & NSControlKeyMask) {
            [NSApp sendAction:self.rightAction to:self.target from:self];
        } else {
            [NSApp sendAction:self.action to:self.target from:self];
        }
    }
    - (void)rightMouseUp:(NSEvent *)event {
        [NSApp sendAction:self.rightAction to:self.target from:self];
    }
    - (void)dealloc {
        self.image = nil;
        [super dealloc];
    }
    - (void)drawRect:(NSRect)rect {
        [self.image drawInRect:self.bounds fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a .NET web developer who has just been asked to produce a small
I'm an ASP.NET developer who has used Microsoft SQL Server for all my database
Can anyone recommend some decent resources for a .NET developer who wishes to get
I am a Winforms and business engine developer who is using asp.net for the
I'm a .Net developer and want to get into developing Silverlight applications. I have
For a developer who likes working in ASP.NET/Web forms, would anyone recommend going towards
I am a C#/.Net developer who just began Java development for Android, and using
As those who have worked on such a project you probably know this site:
I am primarily a .NET developer, and in that sphere alone there are at
As a .NET developer I'm asking whether JBoss alternatives exist to be more suitable

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.