get current focused window id using objective c

倖福魔咒の 提交于 2020-02-23 07:12:01

问题


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);

but no matter which window that i focus at, winNum is always 0.


回答1:


NSWindow *keyTarget = [[NSApplication sharedApplication] keyWindow];
NSInteger winNum = [keyTarget windowNumber];

or in one line:

[[[NSApplication sharedApplication] keyWindow] windowNumber];


来源:https://stackoverflow.com/questions/1692555/get-current-focused-window-id-using-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!