get CGWindow id of focussed window
Do you know how I can get the CGWindow Id of any focussed window (belonging or not to the current applicat开发者_如何学Goion) ?
Thanks in advance for your help :)
Regards,
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.
精彩评论