Files
go_bt/tools/record_aistudio_windows.ps1
2026-09-24 10:57:31 +08:00

56 lines
1.9 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$OutputDir,
[int]$DurationSeconds = 1800
)
$ErrorActionPreference = 'SilentlyContinue'
Add-Type -AssemblyName System.Drawing.Common
Add-Type @'
using System;
using System.Runtime.InteropServices;
public static class AiStudioWindowCapture {
[StructLayout(LayoutKind.Sequential)]
public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
[DllImport("user32.dll")]
public static extern bool IsIconic(IntPtr hWnd);
}
'@
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
$startedAt = Get-Date
$frame = 0
while (((Get-Date) - $startedAt).TotalSeconds -lt $DurationSeconds) {
$windows = Get-Process | Where-Object {
$_.MainWindowHandle -ne 0 -and
$_.MainWindowTitle -match 'Google AI Studio|API keys|Google Cloud'
}
foreach ($process in $windows) {
$handle = [IntPtr]$process.MainWindowHandle
if ([AiStudioWindowCapture]::IsIconic($handle)) { continue }
$rect = New-Object AiStudioWindowCapture+RECT
if (-not [AiStudioWindowCapture]::GetWindowRect($handle, [ref]$rect)) { continue }
$width = $rect.Right - $rect.Left
$height = $rect.Bottom - $rect.Top
if ($width -lt 200 -or $height -lt 150) { continue }
$bitmap = New-Object System.Drawing.Bitmap($width, $height)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
try {
$graphics.CopyFromScreen($rect.Left, $rect.Top, 0, 0, $bitmap.Size)
$frame++
$stamp = Get-Date -Format 'yyyyMMdd_HHmmss_fff'
$safePid = [int]$process.Id
$path = Join-Path $OutputDir ("frame_{0:D5}_{1}_pid{2}.png" -f $frame, $stamp, $safePid)
$bitmap.Save($path, [System.Drawing.Imaging.ImageFormat]::Png)
} finally {
$graphics.Dispose()
$bitmap.Dispose()
}
}
Start-Sleep -Seconds 1
}