首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在苹果电脑上安装FocuesApp

尝试在苹果电脑上安装FocuesApp
EN

Stack Overflow用户
提问于 2013-06-16 01:27:53
回答 1查看 238关注 0票数 1

我试图建立一个程序,输出我几乎所有选定的应用程序。但是由于某种原因,我得到了AXError:-25204。根据参考资料,此错误意味着我试图表示的应用程序正处于繁忙或无响应状态。我不明白为什么..。

我在本教程的指导下工作:http://cocoatutorial.grapewave.com/2010/01/retrieving-the-window-that-has-focus/

代码语言:javascript
复制
#import <Foundation/Foundation.h>
#import <AppKit/NSAccessibility.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

if(!AXAPIEnabled()){
    NSLog(@"AXAPI not Enabled");
    return 0;
}

AXUIElementRef _systemWideElement;
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
CFTypeRef _position;
CFTypeRef _size;
AXError e;


//Get the window that has the focus
//Get the app that has the focus
_systemWideElement = AXUIElementCreateSystemWide();
NSLog(@"%d",_systemWideElement);
e=AXUIElementCopyAttributeValue(_systemWideElement,
                              (CFStringRef)kAXFocusedApplicationAttribute,
                              (CFTypeRef*)&_focusedApp);
NSLog(@"%d,%d",kAXErrorSuccess,e);

e=AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow);
if( e == kAXErrorSuccess) {
    NSLog(@"App ausgewaehlt");

    if(CFGetTypeID(_focusedWindow) == AXUIElementGetTypeID()) {
        //Get the Window's Current Position
        if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
                                         (CFStringRef)NSAccessibilityPositionAttribute,
                                         (CFTypeRef*)&_position) != kAXErrorSuccess) {
            NSLog(@"Can't Retrieve Window Position");
        }
        //Get the Window's Current Size
        if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
                                         (CFStringRef)NSAccessibilitySizeAttribute,
                                         (CFTypeRef*)&_size) != kAXErrorSuccess) {
            NSLog(@"Can't Retrieve Window Size");
        }
    }
    //NSLog(@"%@",_size);

}else {
    NSLog(@"%d",e);
}
[pool drain];
return 0;

}

有人有主意了吗?

EN

回答 1

Stack Overflow用户

发布于 2013-07-25 01:14:00

我相信您应该使用kAXFocusedWindowAttribute,也可能是kAXSizeAttribute,而不是NSAccessibility应用程序接口,它们都是有文档记录的here。根据我的经验,您不希望混合使用这两个API,而是希望使用APIs来访问其他应用程序的元素。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17126140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档