0

我想用 Accessibility API 移动一个窗口。

使用以下代码段

let options = CGWindowListOption(arrayLiteral: CGWindowListOption.excludeDesktopElements, CGWindowListOption.optionOnScreenOnly, CGWindowListOption.optionOnScreenAboveWindow)
let windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) as NSArray? as? [[String: AnyObject]]

for entry  in windowList!
{ if let  bounds = entry[kCGWindowBounds as String] as? [String: Int],
     let owner = entry[kCGWindowOwnerName as String] as? String,
     let pid = entry[kCGWindowOwnerPID as String] as? Int32,
     let windowNumber = entry[kCGWindowNumber as String] as? Int32
  {  print("\(owner)  (\(pid)-\(windowNumber))")
     .....

检测到活动窗口。

对于某些进程(例如注释),我得到具有相同 pid 但不同 windowNumber 的条目。我想要的是移动具有给定 pid 和 windowNumber 的窗口。

我试过这个片段:

let appRef = AXUIElementCreateApplication(pid); 
var value: AnyObject?
let result = AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute as CFString, &value)

if let windowList = value as? [AXUIElement]
{ ...

它返回一个进程的窗口列表。我想用给定的 windowNumber 移动这些窗口之一(来自上面的片段)

我如何找到那个窗口?

4

0 回答 0