如何控制鼠标做各种动作!(0分)

  • 主题发起人 主题发起人 nutian
  • 开始时间 开始时间
N

nutian

Unregistered / Unconfirmed
GUEST, unregistred user!
setcurpos(x,y);其中x,y的单位为像素,值为相对于屏幕的左上角。<br>mouse_event<br>SendMessage<br>=======================================================<br>先getcursorpos()得到鼠标位置,然后setcursorpos()控制鼠标的相对位置, <br>最后在mouse_event事件中模拟点击即可!<br>===========================================<br>控制鼠标自动点击屏幕指定的位置坐标<br>mouse_event(MOUSEEVENTF_MOVE,100,100,0,0);<br>mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br>mouse_event(mouseeventf_leftup,0,0,0,0);<br>===============================================<br>mouse_event(MOUSEEVENTF_MOVE,100,100,0,0);<br>确定的(100,100)是相对于当前鼠标位置的,因而采用这种<br>方法很不好控制到向要点击的位置.<br>SetCursorPos(X,Y)是相对于整个屏幕的,可用<br>SetCursorPos(Left+Image1.Left,Top+20+Image1.Top)来<br>确定鼠标位置其中top+20是留出窗口标题栏.<br>我的测试程序如下:<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>SetCursorPos(Left+Image1.Left+10,Top+20+Image1.Top+10);<br>Mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br>Mouse_event(mouseeventf_leftup,0,0,0,0);<br>end;<br>Image的OnClick事件被调用了.<br>=================================================================先要指定鼠标位置。<br>setcursorpos(x,y); <br>mouse_event(MOUSEEVENTF_LEFTDOWN+MOUSEEVENTF_LEFTUP,x,y,0,0);<br>有时反应时间太短点击对象不会响应,可以加上延时<br>setcursorpos(x,y);<br>mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);<br>sleep(100);<br>mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);<br><br>
 
后退
顶部