Files

40 lines
1.8 KiB
PowerShell

param([int]$RX = 110, [int]$RY = 220, [string]$Out = "C:\Users\admin\AppData\Local\Temp\37du-y.png")
Add-Type -AssemblyName System.Drawing
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WShot {
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
[DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")] public static extern void mouse_event(uint f, uint dx, uint dy, uint d, int e);
public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
}
"@
$proc = Get-Process -Name electron -ErrorAction Stop | Where-Object { $_.MainWindowHandle -ne 0 } | Select-Object -First 1
$hwnd = $proc.MainWindowHandle
$shell = New-Object -ComObject WScript.Shell
$shell.AppActivate($proc.Id) | Out-Null
[WShot]::SetForegroundWindow($hwnd) | Out-Null
Start-Sleep -Milliseconds 900
$rect = New-Object 'WShot+RECT'
[WShot]::GetWindowRect($hwnd, [ref]$rect) | Out-Null
$px = $rect.Left + $RX
$py = $rect.Top + $RY
[WShot]::SetCursorPos($px, $py) | Out-Null
Start-Sleep -Milliseconds 200
[WShot]::mouse_event(0x0002, 0, 0, 0, 0)
[WShot]::mouse_event(0x0004, 0, 0, 0, 0)
Start-Sleep -Milliseconds 300
[WShot]::SetCursorPos($rect.Left + 1200, $rect.Top + 900) | Out-Null
Start-Sleep -Milliseconds 1200
$capW = $rect.Right - $rect.Left
$capH = $rect.Bottom - $rect.Top
$bmp = New-Object System.Drawing.Bitmap $capW, $capH
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.CopyFromScreen($rect.Left, $rect.Top, 0, 0, $bmp.Size)
$g.Dispose()
$bmp.Save($Out, [System.Drawing.Imaging.ImageFormat]::Png)
$bmp.Dispose()
Write-Output "clicked $px,$py"