vb模拟鼠标在固定的位置上单击,可为什么看不见效果

来源:百度知道 编辑:UC知道 时间:2024/07/04 08:07:12
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
在时间控件里的这段代码看不到效果 请各位帮我解释下 谢谢了
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()
Call SetCursorPos(321, 43)
Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Print 1
End Sub

贴出全部代码。要不然就这样的话。一般是你函数常量未定义。
这个只是在当前鼠标点击。而不是移动。如果需要移动的话。需要移动到指定的位置。

回复
'//看。这样的话。我已经回复你了。就是常量未定义

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_LEFTDOWN = &H2 '//加上这两句就可以
Private Const MOUSEEVENTF_LEFTUP = &H4 '//加上这两句就可以

Private Sub Command1_Click()
Call SetCursorPos(321, 43)
Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Print 1
End Sub

把时间控件的时间间隔变下一点