本文介绍了使用目标 c 获取当前聚焦窗口 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用目标 c 获取当前聚焦窗口 id,返回值应该是 int,非常感谢帮助!我只需要让以下行工作
how can i get current focused window id using objective c, the return value should be an int, help is highly appreciated! I just need to get the following line working
CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winNum, kCGWindowImageBoundsIgnoreFraming);
但无论我关注哪个窗口,winNum 始终为 0.
but no matter which window that i focus at, winNum is always 0.
推荐答案
NSWindow *keyTarget = [[NSApplication sharedApplication] keyWindow];
NSInteger winNum = [keyTarget windowNumber];
或在一行中:
[[[NSApplication sharedApplication] keyWindow] windowNumber];
这篇关于使用目标 c 获取当前聚焦窗口 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!