Как щелкнуть по защищенному приложению Powershell

Есть защищённая программа, на которую нужно нажать. Я уже попробовал этот скрипт.

Скрипт работает нормально в других приложениях, но не в нужном мне. Щелчок по нужному приложению не выполняется, а если приложение находится в фокусе, мышь даже не перемещается в заданные в скрипте координаты. Однако, если я убираю мышь с окна, скрипт начинает работать.

# Source - https://stackoverflow.com/questions/39353073/how-i-can-send-mouse-click-in-powershell
# Posted by StephenP
# Retrieved 05.11.2025, License - CC-BY-SA 4.0
$cSource = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Clicker
{
    [StructLayout(LayoutKind.Sequential)]
    struct INPUT
    {
        public int        type;
        public MOUSEINPUT mi;
    }
    [StructLayout(LayoutKind.Sequential)]
    struct MOUSEINPUT
    {
        public int    dx;
        public int    dy;
        public int    mouseData;
        public int    dwFlags;
        public int    time;
        public IntPtr dwExtraInfo;
    }
    const int MOUSEEVENTF_MOVE       = 0x0001;
    const int MOUSEEVENTF_LEFTDOWN   = 0x0002;
    const int MOUSEEVENTF_LEFTUP     = 0x0004;
    const int MOUSEEVENTF_ABSOLUTE   = 0x8000;
    const int screen_length = 0x10000;
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
    public static void LeftClickAtPoint(int x, int y)
    {
        INPUT[] input = new INPUT[3];
        input[0].mi.dx = x * (65535 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
        input[0].mi.dy = y * (65535 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
        input[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
        input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
        input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
        SendInput(3, input, Marshal.SizeOf(input[0]));
    }
}
'@
Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing

# Бесконечный цикл с кликом каждые 5 секунд
while ($true) {
    [Clicker]::LeftClickAtPoint(600, 600)
    Start-Sleep -Seconds 5
}

Ответы (0 шт):