如何在 Windows 远程计算机上运行 mouse_event?

问题描述 投票:0回答:1

我有这段代码,用于使用 WinAppDriver 单击特定点进行 UI 测试。 在本地计算机上没问题,但我的代码应该从本地计算机运行,但在远程计算机上执行。

测试的其余部分由 WinAppDriver 和 Appium 服务器处理,但这部分不起作用,因为它是在我的本地计算机上执行的。

我该怎么做?

class ClickSimulator
{
    [DllImport("user32.dll")]
    static extern bool SetCursorPos(int X, int Y);

    [DllImport("user32.dll")]
    public static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);

    public const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
    public const uint MOUSEEVENTF_LEFTUP = 0x0004;

    public void ClickAtScreenCoordinates(int x, int y)
    {
        SetCursorPos(x, y);
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    }
}
c# appium dllimport winappdriver
1个回答
0
投票

要在 Windows 远程计算机上运行 mouse_event,您可以使用 PsExec 等工具远程执行代码。

例如:

using System.Diagnostics;

class ClickSimulator
{
    public void ClickAtScreenCoordinatesRemote(int x, int y, string remoteMachine)
    {
        Process.Start("psexec.exe", $"\\\\{remoteMachine} -accepteula -nobanner -s -d {System.Reflection.Assembly.GetExecutingAssembly().Location} Click {x} {y}");
    }

    public void Click(int x, int y)
    {
        // Code for local execution
        SetCursorPos(x, y);
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    }
}

使用命令行参数运行您的应用程序:

YourApp.exe Click 123 456
© www.soinside.com 2019 - 2024. All rights reserved.