VB 模拟鼠标右击

来源:百度知道 编辑:UC知道 时间:2024/04/27 18:23:36
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
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 Sub Command1_Click()

SetCursorPos 400, 600
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End Sub

——————————————————
我这个为什么实现不了,哪错了?

估计你没有声明常数MOUSEEVENTF_RIGHTDOWN,完整的程序:

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

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 Const MOUSEEVENTF_RIGHTDOWN = &H8 '====看这里====

Private Sub Command1_Click()
SetCursorPos 416, 325
SetCursorPos 416, 321
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
End Sub
============================================================
参数写错位置了

API是不带vbKeyRButton玩的……

mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0

第一参数为按键,二三参数为鼠标位置偏移,四五参数是关于滚轮什么的的……