<# Screenshots of a running Windows game (exe) for itch.io: starts the game (or uses a running window), then saves the game window every few seconds while you play. Afterwards pick the best. D:\Oculusquest\Projekt\_Tools\Itch\itch_capture.ps1 -Exe release\Spiel.exe -Out docs\itchio\screenshots ... -Title "Gladiator" use an already running window whose title contains this text ... -Every 4 -Count 30 -Delay 8 first shot after 8 s, then every 4 s, 30 shots ... -Hotkey instead of a timer: one shot per press of F9 (Esc ends) Captures what is on screen in the window rectangle (the window must be visible, not covered). Files: raw_001.png, raw_002.png, ... (existing ones are kept, numbering continues). #> param( [string]$Exe, [string]$Title, [string]$Out = 'docs\itchio\screenshots', [int]$Every = 4, [int]$Count = 20, [int]$Delay = 8, [switch]$Hotkey ) $ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.Drawing Add-Type @' using System; using System.Runtime.InteropServices; public static class W32 { [StructLayout(LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; } [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r); [DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr h, int a, out RECT r, int s); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h); [DllImport("user32.dll")] public static extern short GetAsyncKeyState(int k); [DllImport("user32.dll")] public static extern bool SetProcessDPIAware(); } '@ [W32]::SetProcessDPIAware() | Out-Null New-Item -ItemType Directory -Force $Out | Out-Null $proc = $null if ($Exe) { $exePath = (Resolve-Path $Exe).Path $proc = Start-Process $exePath -WorkingDirectory (Split-Path $exePath) -PassThru "Gestartet: $exePath - warte auf das Fenster ..." } function Find-Window { if ($proc) { $proc.Refresh(); if ($proc.MainWindowHandle -ne 0) { return $proc.MainWindowHandle } } if ($Title) { $p = Get-Process | Where-Object { $_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -like "*$Title*" } | Select-Object -First 1 if ($p) { return $p.MainWindowHandle } } if ($proc) { # launchers: the window may belong to a child process with the same name $p = Get-Process -Name $proc.ProcessName -ErrorAction SilentlyContinue | Where-Object MainWindowHandle -ne 0 | Select-Object -First 1 if ($p) { return $p.MainWindowHandle } } return [IntPtr]::Zero } $h = [IntPtr]::Zero for ($i = 0; $i -lt 60 -and $h -eq [IntPtr]::Zero; $i++) { Start-Sleep -Milliseconds 500; $h = Find-Window } if ($h -eq [IntPtr]::Zero) { throw 'Kein Spielfenster gefunden (-Exe oder -Title angeben).' } $n = (Get-ChildItem $Out -Filter 'raw_*.png' -ErrorAction SilentlyContinue | Measure-Object).Count function Snap { $r = New-Object W32+RECT # DWM bounds exclude the invisible resize border of Windows 10/11 windows if ([W32]::DwmGetWindowAttribute($h, 9, [ref]$r, 16) -ne 0) { [W32]::GetWindowRect($h, [ref]$r) | Out-Null } $w = $r.R - $r.L; $hh = $r.B - $r.T if ($w -lt 50 -or $hh -lt 50) { return } $bmp = New-Object System.Drawing.Bitmap $w, $hh $g = [System.Drawing.Graphics]::FromImage($bmp) $g.CopyFromScreen($r.L, $r.T, 0, 0, $bmp.Size) $script:n++ $file = Join-Path $Out ('raw_{0:000}.png' -f $script:n) $bmp.Save($file, [System.Drawing.Imaging.ImageFormat]::Png) $g.Dispose(); $bmp.Dispose() " $file ($w x $hh)" } [W32]::SetForegroundWindow($h) | Out-Null if ($Hotkey) { 'F9 = Screenshot, Esc = fertig. Spiel jetzt im Vordergrund lassen.' while ($true) { if ([W32]::GetAsyncKeyState(0x78) -band 1) { Snap } # F9 if ([W32]::GetAsyncKeyState(0x1B) -band 0x8000) { break } # Esc Start-Sleep -Milliseconds 30 } } else { "Erster Screenshot in $Delay s, dann alle $Every s ($Count Stück). Einfach spielen." Start-Sleep -Seconds $Delay for ($i = 0; $i -lt $Count; $i++) { if ($proc -and $proc.HasExited -and (Find-Window) -eq [IntPtr]::Zero) { 'Spiel beendet.'; break } Snap Start-Sleep -Seconds $Every } } "Fertig: $script:n Screenshots in $((Resolve-Path $Out).Path) - die besten 5-8 behalten, Rest loeschen."