# Send a command to a running WinUAE instance
# Usage: .\run_in_winuae.ps1 [command]
# Default command: mighty.exe
param(
[string]$Command = "mighty.exe"
)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
"@
$process = Get-Process | Where-Object { $_.ProcessName -like "*winuae*" } | Select-Object -First 1
if (-not $process) {
Write-Error "WinUAE is not running."
exit 1
}
$hwnd = $process.MainWindowHandle
if ($hwnd -eq [IntPtr]::Zero) {
Write-Error "WinUAE window handle not found."
exit 1
}
# Restore if minimized (SW_RESTORE = 9), then bring to foreground
[Win32]::ShowWindow($hwnd, 9) | Out-Null
[Win32]::SetForegroundWindow($hwnd) | Out-Null
Start-Sleep -Milliseconds 500
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("$Command{ENTER}")