如何获得所有窗口的列表,目前在屏幕上,在swift? [英] How can I get a list of all windows, currently on the screen, in swift?

查看:775
本文介绍了如何获得所有窗口的列表,目前在屏幕上,在swift?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 swift 中获取屏幕上当前所有窗口的列表, ? (所有示例前面都有 import Cocoa

objective-c 成功运行以下代码:

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);

但是当我在 swift ):

let windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kcGNullWindowID)

我得到一个错误告诉我有一个使用未解决的标识符'kcGNullWindowID'

I get an error telling me that I have an Use of unresolved identifier 'kcGNullWindowID'.

石英文档一段时间我已经得到:

After playing around with the help of the quartz documentation for a while I have gotten to:

let windowList = CGWindowListCopyWindowInfo(CGWindowListOption(kCGWindowListOptionOnScreenOnly), CGWindowListOption(0))

但它仍然不工作, {__ NSArrayM} 对象,我不知道如何访问。

But it still does not work as I am receiving a {__NSArrayM} object, which I do not know how to access.

推荐答案

下面是Swift 2.0中的一个示例,它也展示了多个选项。

Here's an example in Swift 2.0, which also demonstrates multiple options.

    let options = CGWindowListOption(arrayLiteral: CGWindowListOption.ExcludeDesktopElements, CGWindowListOption.OptionOnScreenOnly)
    let windowListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
    let infoList = windowListInfo as NSArray? as? [[String: AnyObject]]

这篇关于如何获得所有窗口的列表,目前在屏幕上,在swift?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆