Add-Type @" using System; using System.Runtime.InteropServices; public class User32 { [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); public const uint WM_KEYDOWN = 0x0100; public const uint WM_KEYUP = 0x0101; } "@ # Set the title or class name of the target window $windowTitle = "Your Window Title" # Find the target window $windowHandle = [User32]::FindWindow([NullString]::Value, $windowTitle) # Check if the window is found if ($windowHandle -ne [IntPtr]::Zero) { # Send a key press (e.g., the 'A' key) [User32]::SendMessage($windowHandle, [User32]::WM_KEYDOWN, [IntPtr]'A', [IntPtr]::Zero) [User32]::SendMessage($windowHandle, [User32]::WM_KEYUP, [IntPtr]'A', [IntPtr]::Zero) } else { Write-Host "Window not found." }