开发者

Obtaining information about the application that owns the active window

开发者 https://www.devze.com 2023-01-07 07:41 出处:网络
I am sure it\'s something easy, and I am not looking to the right documentation. I need to get information about th开发者_JAVA百科e application that handles the active window. The code I need to writ

I am sure it's something easy, and I am not looking to the right documentation.

I need to get information about th开发者_JAVA百科e application that handles the active window. The code I need to write needs to intercept some custom gestures, and return to the application an event that depends from the application itself.


There's the NSWorkspace class from which you can get a dictionary with information about the activeApplication. That application usually owns the "key" window.

Edit: For apps targeting 10.6 or later, activeApplication is deprecated. Here's the new way to go:

NSRunningApplication *activeApplication = nil;
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
    if (app.active) {
        activeApplication = app;
        break;
    }
}


Method activeApplication is deprecated from MacOS 10.7. Documentation suggests to use NSRunningApplication instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消