【问题标题】:Mouse simulation with SendInput使用 SendInput 进行鼠标模拟
【发布时间】:2018-12-10 01:02:31
【问题描述】:

我做了一些自动处理的申请。
它在 C# 中使用了 SendInput
我在我的 PC 上测试了该代码,它运行良好。
但现在我在其他电脑上安装了该应用程序,但它无法正常工作。
我附上了一些代码 sn-p 以供理解。

    public static void ClickLeftMouseButton()
    {
        INPUT mouseDownInput = new INPUT();
        mouseDownInput.type = SendInputEventType.InputMouse;
        mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
        SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

        INPUT mouseUpInput = new INPUT();
        mouseUpInput.type = SendInputEventType.InputMouse;
        mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
        SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
    }
    public static void ClickRightMouseButton()
    {
        INPUT mouseDownInput = new INPUT();
        mouseDownInput.type = SendInputEventType.InputMouse;
        mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
        SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

        INPUT mouseUpInput = new INPUT();
        mouseUpInput.type = SendInputEventType.InputMouse;
        mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
        SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
    }

    public static void SetMousePosition(int x, int y, int width, int height)
    {
        INPUT mouseMoveInput = new INPUT();
        mouseMoveInput.type = SendInputEventType.InputMouse;

        mouseMoveInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_MOVE | MouseEventFlags.MOUSEEVENTF_ABSOLUTE;

        mouseMoveInput.mkhi.mi.dx = 65535 * x / width;
        mouseMoveInput.mkhi.mi.dy = 65535 * y / height;

        SendInput(1, ref mouseMoveInput, Marshal.SizeOf(new INPUT()));
    }

从代码sn-p可以看出,我调用了2个函数。

    MouseSimulator.SetMousePosition(Convert.ToInt16(mAction.x_pos), Convert.ToInt16(mAction.y_pos), 1920, 1080);
    MouseSimulator.ClickLeftMouseButton();

但在另一台 PC 上,它无法正常工作。
我只能通过 Chrome RDP 或 TeamViewer 访问该 PC。
我发布了我的应用程序并在那台 PC 上安装了该软件包。
但是 SendInput 不起作用。
我该怎么办?
2台PC(我的和其他的)的Windows操作系统都是Win10。

【问题讨论】:

  • 您使用该已安装应用程序的用户是否具有管理员权限?尝试检查。或者你的应用程序也有管理员权限。
  • 安装应用程序的用户是管理员。而且两台电脑都是Win10 64bit。
  • 但是现在,如何检查我的应用程序是否有管理员权限?
  • 谢谢,维朱纳夫。我上传了调试编译的文件,并在管理员许可下运行,然后它就可以工作了。

标签: c# mouse simulation sendinput


【解决方案1】:

为了执行SendInput,需要有管理员权限。

【讨论】:

    猜你喜欢
    • 2015-10-15
    • 2018-11-02
    • 2020-11-07
    • 2018-07-13
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多