# shot.ps1 - capture the Solo Arcanum window to a PNG # (for the vision model, which then runs: mtgx feed paste) # # usage: # bin\shot.cmd -> /data/live/shots/YYYYMMDD-HHMMSS.png # bin\shot.cmd -name P1P3 -> P1P3-.png # bin\shot.cmd -process "desktop" -> find window by process name (default) # bin\shot.cmd -activate -> bring the window to front first # # Requires Windows PowerShell 5.1 (built in). No third-party modules. param( [string]$name = "", [string]$process = "desktop", [string]$out = "", [switch]$activate ) $ErrorActionPreference = "Stop" Add-Type -AssemblyName System.Drawing Add-Type @" using System; using System.Runtime.InteropServices; public struct RECT { public int Left, Top, Right, Bottom; } public class Win32 { [DllImport("user32.dll")] public static extern bool SetProcessDPIAware(); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r); [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int cmd); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); } "@ [void][Win32]::SetProcessDPIAware() if (-not $out) { # bin/shot/v/shot.ps1 -> /data/live/shots(向上找到有 README.md 的目录) $root = $PSScriptRoot while ($root -and -not (Test-Path -Path (Join-Path $root "README.md"))) { $root = Split-Path -Parent $root } if (-not $root) { $root = $PSScriptRoot } $out = Join-Path $root "data\live\shots" } function Get-TargetWindow { # 1) by process name (desktop.exe is Solo Arcanum's main program) foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) { if ($p.MainWindowHandle -ne 0 -and $p.ProcessName -like $process) { return $p.MainWindowHandle } } # 2) fall back to the foreground window $fg = [Win32]::GetForegroundWindow() if ($fg -ne 0) { return $fg } return 0 } $h = Get-TargetWindow if ($h -eq 0) { Write-Error "no window found for process '$process'; start Solo Arcanum or pass -process" exit 1 } if ($activate) { [void][Win32]::ShowWindow($h, 9) # SW_RESTORE [void][Win32]::SetForegroundWindow($h) Start-Sleep -Milliseconds 250 } if ([Win32]::IsIconic($h)) { Write-Error "window is minimized; use -activate or restore it first" exit 1 } $r = New-Object RECT [void][Win32]::GetWindowRect($h, [ref]$r) $w = $r.Right - $r.Left $hgt = $r.Bottom - $r.Top if ($w -le 0 -or $hgt -le 0) { Write-Error "bad window size: ${w}x${hgt}" exit 1 } New-Item -ItemType Directory -Force -Path $out | Out-Null $stamp = Get-Date -Format "HHmmss" if ($name) { $file = Join-Path $out ("{0}-{1}.png" -f $name, $stamp) } else { $file = Join-Path $out ("{0}.png" -f (Get-Date -Format "yyyyMMdd-HHmmss")) } $bmp = New-Object System.Drawing.Bitmap $w, $hgt $g = [System.Drawing.Graphics]::FromImage($bmp) $g.CopyFromScreen($r.Left, $r.Top, 0, 0, $bmp.Size) $bmp.Save($file, [System.Drawing.Imaging.ImageFormat]::Png) $g.Dispose() $bmp.Dispose() Write-Output $file