Detecting input in Mac Plugin

Hi,

I am making a plugin that will inform my Mac application of various input events like trackpad swipe/pinch etc. For now I am just trying to get the plugin to be able to detect a mouseDown event but nothing I have tried has been successful.

In TrackPad.h:

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

@interface TrackPad : NSWindow <NSWindowDelegate> {
    
}
@end

extern "C" {
extern bool IsMouseDown();
}

and in TrackPad.m:

#import "TrackPad.h"
#import <Cocoa/Cocoa.h>


@implementation TrackPad

static bool bIsDown = false;

#pragma mark NSResponder

- (void) mouseDown:(NSEvent *)event
{
    bIsDown = true;
}

@end

bool IsMouseDown()
{
	return bIsDown;
}

The mouseDown function is never entered and I have no clue as to why not? Anybody have any ideas?

Ancient question, but I am trying to do the same thing. I’m not sure if the original code posted will accomplish anything, but I have able to listen for events using this: addGlobalMonitorForEventsMatchingMask:handler: | Apple Developer Documentation

Unfortunately, Unity seems to eat events that are given to its window. Events outside Unity are caught just fine. I would love to be able to listen from my Mac Plugin to events that are given to Unity.

edit:

In case anyone stumbles upon this thread, I managed to get something working, although I still don’t understand all the details and it doesn’t work in the editor. I modified code from here: https://blog.reigndesign.com/blog/unity-native-plugins-os-x/