我有两个模拟鼠标左键单击的脚本并关闭程序。 我遇到的问题是我无法使代码在Windows Combapbility for Windows XP Service Pack 2的应用程序上运行良好。
否则我没有任何问题。
Option Explicit On
Public Class Form1
Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 0
For i = 0 To 100
Sleep(1000)
Do_LMouseClick()
Next
For Each p As Process In Process.GetProcesses()
If p.ToString() = "System.Diagnostics.Process (nwmain)" Then
p.Kill()
End If
Next
End Sub
Sub Do_LMouseClick()
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
End Class
这是在C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;
namespace SimulateClick_nwn_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Comenzar_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
InputSimulator input = new InputSimulator();
input.Mouse.LeftButtonClick();
System.Threading.Thread.Sleep(1000);
}
}
}
}
我该如何做到这一点?