OS X events cannot be catched

Hi all,

I created a class to catch OS X events like mouse, tablet… Unfortunately the events are not dispatched to my class. I had a look in the Juce classes and it seems that Juce is catching the events before they are dispatched to me. In other environments the code is working. (OS X Native, Java JNI).

@interface  TabletFocusApplication : NSApplication {
}

- (void) sendEvent:(NSEvent *)event;

@end

@implementation TabletFocusApplication

/**
 * @Override sendEvent
 */
- (void) sendEvent:(NSEvent *)event
{
    switch ( [event type] ) {
		case NSTabletPoint:
                        
			break;
    }
    [super sendEvent: event];
}

@end

What can I do?

Thanks,
Rüdi

Can’t you use the nsnotificationmanager to register your callback for the events you need?

Hi Jules,

thanks for your reply!

I tried this out and I get notifications for the tablet events.

What I don’t know how to get the NSEvent from the NSNotification.

I added a Observer:

	[[NSNotificationCenter defaultCenter]
	 addObserver:self
	 selector:@selector(eventHandler:)
	 name:nil
	 object:nil ]; 

Then I get the notifications here:

-(void)eventHandler: (NSNotification *) event
{
}

Now I need to delegate it to the sendEvent method:

- (void) sendEvent:(NSEvent *)event
{
    switch ( [event type] ) {
...

Cheers,
Rüdi

What are you actually trying to do? Maybe it’s a feature that I could add to the library.

Hi Jules,

I try to add Tablet support to my app. For that I must catch the tablet driver events. As I mentioned before, under native OS X and from a Java virtual machine I can get them by overriding the sendEvent method.

Cheers,
Rüdi

Well, juce already creates MouseEvent objects - wouldn’t it make more sense to just extend the juce native code to add the tablet data that you need to the MouseEvent, rather than trying to bodge the same functionality as a parallel to what’s already there?

Hi Jules,

that would be a possibility. But where can I do this?

Thanks,
Rüdi

I guess the place to start would be juce_mac_NSViewComponentPeer.mm

Hi Jules,

hmm, I really don’t knwo what to do there. I can’t find where you ovveride the sendEvent method.

Another problem is that I cannot InstallEventHandlers in the juce environment.

EventTypeSpec	tabletPointerEvent = { kEventClassTablet, kEventTabletPointer	};
OSErr			status = noErr;
status = InstallEventHandler( GetEventMonitorTarget(), NewEventHandlerUPP( HandleTabletPointer ), 1, &tabletPointerEvent, NULL, NULL );

This code works well in OS X native and within a Java virtual machine.

Can’t you give me a hint, where these events are swallowed?

Thanks,
Rüdi

InstallEventHandler is an old carbon function - best avoided.

What’s the obsession with overriding sendEvent? The whole point of events is that you receive them in the object that they were sent to - you can’t globally intercept them all and do a big switch statement! Presumably these tablet events end up arriving at some kind of NSView callback, so that’s where you’d get their data and use it.

Hi Jules,

obsession? It’s the recommended source code by wacom.

InstallEventHandler. Sure I know it’s a hack, but the only way to get the Tablet events while the app has not the focus. So I need it anyway.

I don’t know what you mean with the NSView callback.

Thanks,
Rüdi

Well shame on them if that’s true!

30 seconds searching through the docs for “tablet” and I see that NSResponder (and an NSView is an NSResponder) has a bunch of methods tabletPoint: tabletProximity:, etc. That’s clearly where you’re supposed to receive these things.

Hi Jules,

got it.

Just for you to know:

-Background Events:
InstallEventHandler does not work with the Base SDK 10.4 and Juce. Don’t know why. In OS X native I had no problems. So changing to SDK 10.5 solved the issue.
As I have seen, this function will also work with 64 bit and will not be deleted in further OS X releases. There is a new approach to get the background events in 10.6:

	[NSEvent 	addGlobalMonitorForEventsMatchingMask:(NSEventMask)observedTypes handler:^(NSEvent* theEvent)
       ...

But this is not running in 10.4 or 10.5, so I have to use InstallEventHandler the next years :slight_smile:

  • Foreground events
    Solved it with an extension of juce_mac_NSViewComponentPeer.mm

Many thanks for your help!!!
Rüdi

Ah, it’s so annoying when they keep changing the APIs like that!