3

我有以下代码:

id eventHandler = [NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent * event) {
    CGWindowID windowID = (CGWindowID)[event windowNumber];
    CFArrayRef a = CFArrayCreate(NULL, (void *)&windowID, 1, NULL);
    NSArray *windowInfos = (__bridge NSArray *)CGWindowListCreateDescriptionFromArray(a);
    CFRelease(a);
    if ([windowInfos count] > 0) {
        NSDictionary *windowInfo = [windowInfos objectAtIndex:0];
        NSLog(@"Name:  %@", [windowInfo objectForKey:(NSString *)kCGWindowName]);
        NSLog(@"Owner: %@", [windowInfo objectForKey:(NSString *)kCGWindowOwnerName]);
        //etc.
    }
}];

这在识别光标下的窗口方面做得很好。但是,为了可靠地识别它们,您必须单击窗口。某些窗口会触发终端和 xcode 等更改,但悬停在桌面上不会触发 Finder 在光标下。但是,如果您单击桌面,则可以正确识别它。有什么想法我可能会错过吗?

4

0 回答 0