1、首先添加using System.Runtime.InteropServices;
2、为鼠标添加模拟点击的各种参数
//鼠标事件 因为我用的不多,所以其他参数没有写
1
2
3
4
5
6
7
8
|
private
readonly
int
MOUSEEVENTF_LEFTDOWN = 0x0002;
//模拟鼠标移动
private
readonly
int
MOUSEEVENTF_MOVE = 0x0001;
//模拟鼠标左键按下
private
readonly
int
MOUSEEVENTF_LEFTUP = 0x0004;
//模拟鼠标左键抬起
private
readonly
int
MOUSEEVENTF_ABSOLUTE = 0x8000;
//鼠标绝对位置
private
readonlyint MOUSEEVENTF_RIGHTDOWN = 0x0008;
//模拟鼠标右键按下
private
readonlyint MOUSEEVENTF_RIGHTUP = 0x0010;
//模拟鼠标右键抬起
private
readonlyint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
//模拟鼠标中键按下
private
readonlyint MOUSEEVENTF_MIDDLEUP = 0x0040;
// 模拟鼠标中键抬起
|
3、为鼠标点击添加点击函数
1
2
3
4
5
6
|
public
static
extern
void
mouse_event(
int
dwFlags,
int
dx,
int
dy,
int
dwData,
int
dwExtraInfo);
private
void
button2_Click(
object
sender, EventArgs e) {
int
x =
int
.Parse(textBox1.Text);
int
y =
int
.Parse(textBox2.Text);
//绝对位置 mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x * 65535 / 1600, y * 65535 / 900, 0, 0);//移动到需要点击的位置 mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, x * 65535 / 1600, y * 65535 / 900, 0, 0);//点击 mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, x * 65535 / 1600, y * 65535 / 900, 0, 0);//抬起
mouse_event(MOUSEEVENTF_MOVE , x , y, 0, 0);
//移动 mouse_event(MOUSEEVENTF_LEFTDOWN , x , y, 0, 0);//点击 mouse_event(MOUSEEVENTF_LEFTUP , x , y , 0, 0);//抬起
}
|