VB模拟鼠标

来源:百度知道 编辑:UC知道 时间:2024/05/26 07:43:45
VB中模拟键盘用SENDKEY,那么模拟鼠标用什么呢?

Public 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)
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal y As Long) As Long

要用这两个API
先和SetCursorPos设置鼠标位置
再用其 mouse_event 模拟鼠标点击

mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
这个代码,模拟了一次鼠标左键的点击,注意先声明常量及相应的API

用api函数
我简单写了一个,你运行一下就明白了

模块中:
'模拟鼠标动作
Public 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)

'设定鼠标位置
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MO