如何使用目标c获取当前聚焦的窗口id,返回值应为int,非常感谢帮助!我只需要让以下一行工作
CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winNum, kCGWindowImageBoundsIgnoreFraming);
但无论我关注哪个窗口,winNum始终为0。
答案 0 :(得分:7)
NSWindow *keyTarget = [[NSApplication sharedApplication] keyWindow];
NSInteger winNum = [keyTarget windowNumber];
或一行:
[[[NSApplication sharedApplication] keyWindow] windowNumber];