一、首先添加using System.Runtime.InteropServices;函數
二、爲鼠標添加模擬點擊的各類參數spa
//鼠標事件 由於我用的很少,因此其餘參數沒有寫code
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;
// 模擬鼠標中鍵擡起
|
三、爲鼠標點擊添加點擊函數 事件
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);//擡起
}
|