Converting MouseDown in Xcode to MacOSLib

I’m trying to recreate a few classes I made in Xcode in the hopes of improving on a project. In a custom NSStatusItem subclass, I have the following code to detect a mouse click and then call a function “menuletClicked” in the StatusItem’s delegate.

- (void)mouseDown:(NSEvent *)event {
    NSLog(@"Mouse down event: %@", event);
    [self.delegate menuletClicked];
}

I’m trying to figure out how I can do this using MacOSLib. I created a subclass of Cocoa.NSStatusItem. How would I go about doing so with declares? I tried

declare sub mouseDown lib CocoaLib selector "mouseDown:" (theEvent as Cocoa.NSEvent)

but it doesn’t work, and I think maybe I’m doing it wrong. Any ideas? Thanks.

Handling an Objc-C event is quite a bit of work. There is example code in the MacOSLib.

The other way to do it would be to grab the mouse location. Then convert it against the NSStatusItem ViewRef

[code] declare function mouseLocationOutsideOfEventStream lib cocoaLibrary selector “mouseLocationOutsideOfEventStream” ( winHandle as Ptr ) as NSPoint
dim mousePosition as NSPoint = mouseLocationOutsideOfEventStream( viewWindow )

declare function convertPoint lib cocoaLibrary selector “convertPoint:fromView:” ( ref as integer, inPoint as NSPoint, fromView as Ptr ) as NSPoint
mousePosition = convertPoint( inControlRef, mousePosition, nil )[/code]

Hi Sam, thanks for that. Unfortunately I don’t think it will be able to help me because I don’t want to have a timer constantly call these functions which could slow my app. I think I might have found the code in MacOSLib. Do functions like “objc_allocateClassPair” and “class_addMethod” and the code in this discussion here sound right? If so I think be able to get it to work with a little guess and check, but any advice or tips you have would be greatly appreciated. Thanks

I’ve never worked with the NSStatusItem, but you should be use this code in the mouse down event, if there is one. Otherwise I might suggest starting a new thread, with NSStatusItem in the title, so that people who have worked with it can give you some advice.

Unfortunately there is no mouse down event. Ill take your advice and start a new thread. Thanks for the help.