first commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
|
||||
Add-Type @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public class Win32 {
|
||||
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
|
||||
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT r);
|
||||
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
}
|
||||
"@
|
||||
|
||||
$root = "c:\Users\32453\CodeBuddy\20260825142915\TempleRun"
|
||||
$exe = Join-Path $root "bin\Release\net8.0-windows\TempleRun.exe"
|
||||
$out = Join-Path $root "_shot"
|
||||
New-Item -ItemType Directory -Force -Path $out | Out-Null
|
||||
|
||||
$p = Start-Process -FilePath $exe -PassThru
|
||||
Start-Sleep -Seconds 3
|
||||
$p.Refresh()
|
||||
|
||||
function Grab([string]$name) {
|
||||
$h = $p.MainWindowHandle
|
||||
if ($h -eq [IntPtr]::Zero) { Write-Output "no window"; return }
|
||||
[Win32]::SetForegroundWindow($h) | Out-Null
|
||||
Start-Sleep -Milliseconds 700
|
||||
$r = New-Object 'Win32+RECT'
|
||||
[Win32]::GetWindowRect($h, [ref]$r) | Out-Null
|
||||
$w = $r.Right - $r.Left
|
||||
$ht = $r.Bottom - $r.Top
|
||||
if ($w -le 0 -or $ht -le 0) { Write-Output "bad rect $w x $ht"; return }
|
||||
$bmp = New-Object System.Drawing.Bitmap $w, $ht
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.CopyFromScreen($r.Left, $r.Top, 0, 0, $bmp.Size)
|
||||
$path = Join-Path $out "$name.png"
|
||||
$bmp.Save($path, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose(); $bmp.Dispose()
|
||||
Write-Output "saved $name : $w x $ht"
|
||||
}
|
||||
|
||||
Grab "01_ready"
|
||||
|
||||
[System.Windows.Forms.SendKeys]::SendWait(" ")
|
||||
Start-Sleep -Seconds 4
|
||||
Grab "02_playing"
|
||||
|
||||
Start-Sleep -Seconds 4
|
||||
Grab "03_playing2"
|
||||
|
||||
try { $p.Kill() } catch {}
|
||||
Write-Output "exit=$($p.HasExited)"
|
||||
Reference in New Issue
Block a user