param([string]$Title, [string]$ReadyFile, [switch]$Cover, [int]$Width=500, [int]$Height=300, [switch]$PerMonitorDpi, [switch]$NormalWindow) if ($PerMonitorDpi) { Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class FixtureDpi { [DllImport("user32.dll")] public static extern IntPtr SetThreadDpiAwarenessContext(IntPtr c); }' [void][FixtureDpi]::SetThreadDpiAwarenessContext([IntPtr](-4)) } Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $form = New-Object System.Windows.Forms.Form $form.Text = $Title $form.Size = New-Object System.Drawing.Size($Width, $Height) $form.StartPosition = 'Manual' $form.Location = New-Object System.Drawing.Point(100, 100) $form.TopMost = -not $NormalWindow $form.BackColor = if ($Cover) { [System.Drawing.Color]::Magenta } else { [System.Drawing.Color]::Lime } $label = New-Object System.Windows.Forms.Label $label.Text = if ($Cover) { 'OCCLUDER - NOT TEST EVIDENCE' } else { 'ARTEMIS window capture fixture' } $label.Location = New-Object System.Drawing.Point(20, 25) $label.AutoSize = $true $form.Controls.Add($label) $button = New-Object System.Windows.Forms.Button $button.Text = 'Capture coordinate target' $button.AccessibleName = 'Capture coordinate target' $button.Location = New-Object System.Drawing.Point(100, 100) $button.Size = New-Object System.Drawing.Size(180, 50) $button.BackColor = [System.Drawing.Color]::Red $button.Add_Click({ [System.IO.File]::WriteAllText(($ReadyFile + '.clicked'), 'clicked') }) $button.Add_MouseDown({ param($sender, $event) [System.IO.File]::AppendAllText(($ReadyFile + '.mouse'), "down:$($event.X),$($event.Y)`n") }) $button.Add_MouseUp({ param($sender, $event) [System.IO.File]::AppendAllText(($ReadyFile + '.mouse'), "up:$($event.X),$($event.Y)`n") }) $form.Controls.Add($button) $timer = New-Object System.Windows.Forms.Timer $timer.Interval = 120000 $timer.Add_Tick({ $form.Close() }) $form.Add_Shown({ [System.IO.File]::WriteAllText($ReadyFile, $PID.ToString()) $timer.Start() }) try { [System.Windows.Forms.Application]::Run($form) } finally { $timer.Dispose(); $form.Dispose() }