18 lines
908 B
Swift
Executable file
18 lines
908 B
Swift
Executable file
import Cocoa
|
|
func moveMouse(_ x: CGFloat, _ y: CGFloat) {
|
|
let ev = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: CGPoint(x: x, y: y), mouseButton: .left)
|
|
ev?.post(tap: .cghidEventTap)
|
|
}
|
|
func capture(_ name: String) {
|
|
let rect = CGRect(x: 349, y: 159, width: 1161, height: 1102)
|
|
guard let img = CGWindowListCreateImage(rect, .optionOnScreenOnly, kCGNullWindowID, [.boundsIgnoreFraming, .nominalResolution]) else { print("capture fail"); return }
|
|
let url = URL(fileURLWithPath: name)
|
|
guard let dest = CGImageDestinationCreateWithURL(url as CFURL, "public.png" as CFString, 1, nil) else { return }
|
|
CGImageDestinationAddImage(dest, img, nil)
|
|
CGImageDestinationFinalize(dest)
|
|
print("captured \(name) \(img.width)x\(img.height)")
|
|
}
|
|
moveMouse(1900, 1350); usleep(600_000)
|
|
capture("away.png")
|
|
moveMouse(849, 707); usleep(700_000)
|
|
capture("over.png")
|