Re: Help to understand how do events work
Re: Help to understand how do events work
- Subject: Re: Help to understand how do events work
- From: "email@hidden" <email@hidden>
- Date: Wed, 6 Oct 2010 13:36:02 +0100
On 6 Oct 2010, at 12:39, eveningnick eveningnick wrote:
> Hello!
> I have created a cocoa application that has unusual behavior: it has a
> window (NSPanel), which does not activate the application, when it's
> clicked. This window is ordered always on top of the other windows. So
> it's like a "tooltip" window (basically it is a popup thing, that
> drops down when a user types some combination of symols in another
> application - which is a texteditor).
> Anyway, i did it as following:
> NSPanel *popupWindow = [[NSPanel alloc]
> initWithContentRect:NSMakeRect(100,100,300,100)
> styleMask:NSNonactivatingPanelMask | NSTitledWindowMask
> backing:NSBackingStoreBuffered defer:NO];
> [popupWindow setLevel:NSPopupMenuWindowLevel];
>
> then i am showing it:
> [popupWindow makeKeyAndOrderFront:nil];
>
> This "window" behaves as expected: it is displayed on top of all
> others, even if it's Application (in Dock, for ex) is not active. It
> also dispatches all the clicks on controls (like NSPushButton's) to
> these controls.
>
> The problem for me is that i want to receive keyDown events with it.
Have a look at NSWindow -sendEvent:
If you subclass your window you can override -sendEvent: and access the event stream like so:
/*
send event
This action method dispatches mouse and keyboard events sent to the window by the NSApplication object.
*/
- (void)sendEvent:(NSEvent *)event
{
// look for key down
if ([event type] == NSKeyDown) {
// process the event
}
[super sendEvent:event];
}
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com
_______________________________________________
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