VB postmessage 鼠标单击位置
1个回答
展开全部
这个很简单啊,不就是模拟鼠标点击吗?
看下面的代码帮你解决问题:
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) '设置鼠标指针在屏幕中的位置
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '这个是设置鼠标的位置!
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '延时
Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下消息
Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起消息
Const MOUSEEVENTF_RIGHTDOWN = &H8 '模拟鼠标右键按下消息
Const MOUSEEVENTF_RIGHTUP = &H10 '模拟鼠标右键抬起消息
Const MOUSEEVENTF_MOVE = &H1 '模拟鼠标移动消息
Private Sub Form_Click()
Sleep 5000
SetCursorPos 172, 190 '设置鼠标指针在屏幕中的位置
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '模拟鼠标动作
mouse_event MOUSEEVENTF_MOVE, 0, 0, 0, 0 '模拟鼠标动作
SetCursorPos 614, 293 '设置鼠标指针在屏幕中的位置
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标动作
End Sub
看下面的代码帮你解决问题:
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) '设置鼠标指针在屏幕中的位置
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '这个是设置鼠标的位置!
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '延时
Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下消息
Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起消息
Const MOUSEEVENTF_RIGHTDOWN = &H8 '模拟鼠标右键按下消息
Const MOUSEEVENTF_RIGHTUP = &H10 '模拟鼠标右键抬起消息
Const MOUSEEVENTF_MOVE = &H1 '模拟鼠标移动消息
Private Sub Form_Click()
Sleep 5000
SetCursorPos 172, 190 '设置鼠标指针在屏幕中的位置
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 '模拟鼠标动作
mouse_event MOUSEEVENTF_MOVE, 0, 0, 0, 0 '模拟鼠标动作
SetCursorPos 614, 293 '设置鼠标指针在屏幕中的位置
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标动作
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询