tags:

views:

59

answers:

1

Hello,

Do you know how I can get the CGWindow Id of any focussed window (belonging or not to the current application) ?

Thanks in advance for your help :)

Regards,

+1  A: 

One way is to use CGWindowListCopyWindowInfo to get the list of all windows like this:

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);

Examine this list to find all the windows at window level 0 (these are the normal windows).

I'm fairly certain that the array returned will be in the order the windows are layered on the screen. If not, you can sort by the "windowOrder" key. Look at the SonOfGrab sample code for more on how to use this API.

Ken Aspeslagh
This is the opton I wanted to avoid if there was directly a function providing me this.Thanks for your help.
AP