tags:

views:

28

answers:

2

I am making a application that the user will have to interact with one window and when they have that window configured the way they want it they switch to a different application then my application will begin to do other stuff which i will have defined in a method

say for an example program when the main window has focus it contains a label that says "i am focused" and when the person clicks on the desktop or another window/application then the label will read "i am not focused".

Thanks

A: 

[NSWindow isKeyWindow] might be what you're looking for.

Indicates whether the window is the key window for the application.

- (BOOL)isKeyWindow

Return Value YES if the window is the key window for the application; otherwise, NO.

If you want to detect when your window becomes key, or when it stops being key, check out the NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification notifications.

robinjam
+1  A: 

That is not the same as key window. Key window means that you will receive input events for your application. What you want to know is whether your application is in the foreground. What you're looking for is the NSApplication notifications NSApplicationDidBecomeActiveNotification and NSApplicationDidResignActiveNotification. Observe those to discover when your application is or isn't in the foreground. Your application delegate's applicationDidBecomeActive: and applicationDidResignActive: will automatically be called on these events.

Rob Napier
+1 for a better response than mine.
robinjam
Thanks it was exactly what I was working for! now if only i could get the code inside the method to work correctly
Zanok
Zanok: It's worth clarifying that windows are separate from applications in Mac OS X. An application can and does have multiple windows. You need to decide whether you care about the active window (as opposed to the other windows in your application, including the About panel, Font panel, Color panel, and perhaps Preferences panel) or the active application (as opposed to another application).
Peter Hosey