有关模拟鼠标的问题 ( 积分: 30 )

  • 主题发起人 主题发起人 bin2000
  • 开始时间 开始时间
B

bin2000

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在屏幕上某个点(x,y)模拟鼠标单击,但用户看不到鼠标移动,程序如下,无论我怎么<br>设置dx,dy的值,鼠标还是在原地单击,这是怎么回事?<br><br> &nbsp;minput.Itype := INPUT_MOUSE;<br> &nbsp;minput.mi.dx := x;<br> &nbsp;minput.mi.dy := y;<br> &nbsp;minput.mi.dwflags := MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_ABSOLUTE;<br> &nbsp;minput.mi.dwExtraInfo := 0;<br> &nbsp;minput.mi.time := 0;<br> &nbsp;minput.mi.mouseData :=0;<br> &nbsp;SendInput(1, minput, sizeof(minput));<br><br> &nbsp;minput.Itype := INPUT_MOUSE;<br> &nbsp;minput.mi.dx := x;<br> &nbsp;minput.mi.dy := y;<br> &nbsp;minput.mi.dwExtraInfo := 0;<br> &nbsp;minput.mi.time := 0;<br> &nbsp;minput.mi.mouseData :=0;<br> &nbsp;minput.mi.dwflags := MOUSEEVENTF_LEFTUP or MOUSEEVENTF_ABSOLUTE;<br> &nbsp;SendInput(1, minput, sizeof(minput));
 
我想在屏幕上某个点(x,y)模拟鼠标单击,但用户看不到鼠标移动,程序如下,无论我怎么<br>设置dx,dy的值,鼠标还是在原地单击,这是怎么回事?<br><br> &nbsp;minput.Itype := INPUT_MOUSE;<br> &nbsp;minput.mi.dx := x;<br> &nbsp;minput.mi.dy := y;<br> &nbsp;minput.mi.dwflags := MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_ABSOLUTE;<br> &nbsp;minput.mi.dwExtraInfo := 0;<br> &nbsp;minput.mi.time := 0;<br> &nbsp;minput.mi.mouseData :=0;<br> &nbsp;SendInput(1, minput, sizeof(minput));<br><br> &nbsp;minput.Itype := INPUT_MOUSE;<br> &nbsp;minput.mi.dx := x;<br> &nbsp;minput.mi.dy := y;<br> &nbsp;minput.mi.dwExtraInfo := 0;<br> &nbsp;minput.mi.time := 0;<br> &nbsp;minput.mi.mouseData :=0;<br> &nbsp;minput.mi.dwflags := MOUSEEVENTF_LEFTUP or MOUSEEVENTF_ABSOLUTE;<br> &nbsp;SendInput(1, minput, sizeof(minput));
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br> &nbsp;Shift: TShiftState);<br>Var<br> &nbsp;x, y : Integer;<br> &nbsp;MousePoint : TPoint;<br>begin<br> &nbsp;if Key=vk_F5 then begin<br> &nbsp; &nbsp;MousePoint.X := StrToInt(edt1.Text);<br> &nbsp; &nbsp;MousePoint.Y := StrToInt(edt2.Text);<br> &nbsp; &nbsp;SetCursorPos(MousePoint.X, MousePoint.Y);<br> &nbsp; &nbsp;mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);<br> &nbsp; &nbsp;mouse_event(MOUSEEVENTF_LEFTUP, &nbsp; X, Y, 0, 0);<br> &nbsp;end;<br>end;
 
用SetCursorPos我也可以做到,只是用户能看见鼠标移动,我不想让用户看见。
 
sendmessage不行吗?
 
var<br> &nbsp;XPos,YPos:integer;<br> &nbsp;Handle:HWND;<br>begin<br> &nbsp;Handle:=WindowFromPoint(point(xPos,yPos));<br> &nbsp;PostMessage(Handle,WM_LBUTTONDOWN ,0,MakeLParam(xPos,yPos));<br> &nbsp;PostMessage(Handle,WM_LBUTTONUP ,0,MakeLParam(xPos,yPos));<br>end;
 
to daqun:<br> &nbsp;我试过了,不行,用sendinput至少还有单击事件发生,只是地点不是我预想的,<br>用postmessage或者sendmessage连单击事件都没有。<br>还有人帮我吗?
 
SendMessage(你要按的按钮的句柄, WM_LBUTTONDOWN, 0, 0);<br>SendMessage(你要按的按钮的句柄, WM_LBUTTONUP, 0, 0);
 
后退
顶部