Cocoa equivalent for 'InstallApplicationEventHandler'
Cocoa equivalent for 'InstallApplicationEventHandler'
- Subject: Cocoa equivalent for 'InstallApplicationEventHandler'
- From: Vikram Sethi <email@hidden>
- Date: Sat, 20 Feb 2010 17:15:43 +0530
Hi,
I am rewriting the event handling mechanism of my app in Cocoa. It is in
Carbon as of now. Is there a Cocoa equivant for
InstallApplicationEventHandler(), so that I can listen to event at the
application level? As I understand, as per the NSResponder chain hierarchy,
I can get the events on the NSWindow. However, I would want to do some
special processing in my app in the no-window state as well. Some events
like application activation/deactivation are dispatched to the application
delegate. However, events like keyDown are not handled by the NSApplication
class or its delegate.
In the absence of a true Cocoa equivalent for application or system level
events, one of the ways that comes to mind is to override the "sendEvent"
method of the NSApplication class and prior to calling sendEvent on "super",
do some preprocessing, and then decide whether to propagate that further.
The sendEvent method would look like this.
- (void)sendEvent:(NSEvent *)anEvent
{
bool propagate = [self preProcessEvent:anEvent];
if(propagate)
[super sendEvent:anEvent];
[self postProcessEvent:anEvent];
}
Do you think this approach is okay? What do I stand to loose with this
approach? Do you foresee any problems? Is there a better way to do this?
Any pointers and/or suggestions would be helpful and would be appreciated.
Thanks,
Vikram
P.S. I am not sure if this has been asked earlier. I could not find it.
Pardon me if this is a repeat question.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden