我申请了一些自动处理。
它在C#中使用了SendInput
我在我的PC上测试了这段代码,它运行良好。
但现在我在另一台电脑上安装了这个应用程序,但它不能工作。
我附上了一些代码片段以便于理解。
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()));
}正如你从代码片段中看到的,我调用了2个函数。
MouseSimulator.SetMousePosition(Convert.ToInt16(mAction.x_pos), Convert.ToInt16(mAction.y_pos), 1920, 1080);
MouseSimulator.ClickLeftMouseButton();但在另一台PC上,它无法工作。
我只能通过Chrome RDP或TeamViewer访问那台电脑。
我发布了我的应用程序,并在那台PC上安装了那个包。
但是SendInput不工作。
怎么办?
2台PC(我的和其他的)的Windows操作系统都是Win10。
发布于 2018-12-10 10:22:40
为了执行SendInput,需要拥有管理员权限。
https://stackoverflow.com/questions/53698260
复制相似问题