瑞星卡卡安全论坛

首页 » 技术交流区 » 系统软件 » 如何使用VB控制鼠标在屏幕上移动到一个指定的位置并单击左键??
飞鱼宝宝 - 2006-2-21 20:00:00
如题,先谢谢各位大虾了。
江湖游客 - 2006-2-21 22:15:00
要用到API来控制,VB本身没法做到。
爱上月亮的猪 - 2006-2-22 1:03:00
mouse_event 鼠标模拟事件
声明:
Private Declare Sub mouse_event Lib "user32" ( ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long )

变量:
鼠标左键按下 &H2
鼠标松开 = &H4
鼠标右键按下 &H8
鼠标右键松开 &H10

代码:
Private Declare Sub mouse_event Lib "user32" ( ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long )

mouse_event &H4 Or &H2, 0, 0, 0, 0 '左键单击
mouse_event &H8 Or &H10, 0, 0, 0, 0 '右键单击

'左键双击[就是两次单击]--------
mouse_event &H4 Or &H2, 0, 0, 0, 0
mouse_event &H4 Or &H2, 0, 0, 0, 0



endurer - 2006-2-23 13:02:00
移动鼠标位置可以用API函数SetCursorPos()来完成。

实现“单击左键”的方法,第2楼爱上月亮的猪 给的方法比较好。

另一种实现方法是,先获取鼠标所在位置的控件的句柄,再向该句柄发送WM_KEYDOWN消息


可参考:
玩笑程序2,看看你是否能点中"否"按钮
http://blog.csdn.net/purpleendurer/archive/2005/07/02/410851.aspx
飞鱼宝宝 - 2006-2-23 21:41:00
哈哈,谢谢各位大虾,小生明白了。
1
查看完整版本: 如何使用VB控制鼠标在屏幕上移动到一个指定的位置并单击左键??