vb6.0 api 实现鼠标指定位置 按下鼠标左键并抬起

时间:2022-06-17 10:33:22
例:单击Command1时鼠标会到(500,500)这个点作鼠标左键单击动作。 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() SetCursorPos 500, 500 mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 End Sub dwFlags:标志位集,指定点击按钮和鼠标动作的多种情况。 MOUSEEVENTF_MOVE &H1,移动鼠标 MOUSEEVENTF_LEFTDOWN &H2,模拟鼠标左键按下 MOUSEEVENTF_LEFTUP &H4,模拟鼠标左键抬起 MOUSEEVENTF_RIGHTDOWN &H8,模拟鼠标右键按下 MOUSEEVENTF_RIGHTUP &H10,模拟鼠标右键抬起 MOUSEEVENTF_MIDDLEDOWN &H20,模拟鼠标中键按下 MOUSEEVENTF_MIDDLEUP &H40,模拟鼠标中键抬起 MOUSEEVENTF_ABSOLUTE &H8000,标示是否采用绝对坐标 )