[System.Runtime.InteropServices.DllImport("user32")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
//移动鼠标
const int MOUSEEVENTF_MOVE = 0x0001;
//模拟鼠标左键按下
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
//模拟鼠标左键抬起
const int MOUSEEVENTF_LEFTUP = 0x0004;
//模拟鼠标右键按下
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
//模拟鼠标右键抬起
const int MOUSEEVENTF_RIGHTUP = 0x0010;
//模拟鼠标中键按下
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
//模拟鼠标中键抬起
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
//标示是否采用绝对坐标
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
//
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//keybd_event、SendMessage
private void button1_Click(object sender, EventArgs e)
{
IntPtr hwnd = FindWindow(null, "拼多多工作台");
if (hwnd != IntPtr.Zero)
{
//MessageBox.Show(hwnd+"找到-拼多多工作台");
//SetForegroundWindow(hwnd);
}
else
{
MessageBox.Show("没有找到拼多多工作台");
}
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 335*65536/1920, 135*65536/1080, 0, 0);
SetForegroundWindow(hwnd);
Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTDOWN , 0, 0, 0, 0);
Thread.Sleep(2000);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
注意是 拼多多工作后台,模拟点击这个没有反应,鼠标有移动,对准了这个➕
这个需要怎么解决,希望大神看一下,指导一下