views:

82

answers:

2

Is there a way to have my app's window receive keyboard and/or mouse events (i.e. user clicking on window's buttons) while still retaining focus to another, unrelated app?

I've tried configuring my window at different levels, including [myWindow setLevel:NSPopUpMenuWindowLevel] to no avail.

A: 

You should be able to handle mouse clicks without ordering your window front by making your views (at least the ones that handle mouse clicks) respond to acceptsFirstMouse: messages by sending NSApp a preventWindowOrdering message and then returning YES.

You should not make your app handle typing without ordering itself front. The user might not realize where their typing is going if the field where it's appearing is obscured by another window.

Peter Hosey
Thanks for the tips, though it's still not working the way I want it to.For my window class, I'm overriding canBecomeKeyWindow (returns NO), makeKeyWindow (does nothing), acceptsFirstResponder (returns NO), and canBecomeMainWindow (does nothing).I've also defined as you suggested my own NSButton class to override acceptsFirstMessage:Basically, I need my window to popup and have the user click on its buttons while the previous app (let's say iTunes) remains active with its window and menubar active/in focus.
hishamk
A: 

Found it. Simple, yet elusive.

Use NSPanel and make sure panel style is Non Activating (NSNonactivatingPanelMask) or tick the same option in IB's inspector.

hishamk