delphi_多种鼠标模拟方式
//4种方法模拟
if combobox2.ItemIndex = 0 then
begin
// 1、发送窗口消息Message
//lparam 高16位是y 低16位是 x 算法就是 x+y左移16位
//lparam:=p1.X+ p1.Y shl 16;
sendMessage(WinHandle,WM_LBUTTONDOWN,MK_LBUTTON, MAKELPARAM (p1.X, p1.Y)); //鼠标按下
sleep(40);
sendMessage(WinHandle,WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM (p1.X, p1.Y)); // 鼠标抬起
end;
if combobox2.ItemIndex = 1 then
begin
// 2. 使用 mouse_event
setcursorpos(x0+p1.X,y0+p1.Y);
mouse_event(MOUSEEVENTF_LEFTDOWN,x0+p1.X,y0+p1.Y ,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,x0+p1.X,y0+p1.Y ,0,0);
end;
if combobox2.ItemIndex = 1 then
begin
// 3、 利用sendinput模拟
setcursorpos(x0+p1.X,y0+p1.Y);
SLEEP(200);
SImouseclick(VK_LBUTTON,40);
end;
if combobox2.ItemIndex = 1 then
begin
// 4、WinIo驱动级
setcursorpos(x0+p1.X,y0+p1.Y);
MKmouseclick(mcLeft,200);
end;
1