1.滑鼠左右鍵
2.滑鼠移動位置
3.滑鼠拖曳
首先宣告
'Win32 Api
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)
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Private Const WHEEL_DELTA = 120
Private Const MOUSEEVENTF_WHEEL = &H800
Dim result As Boolean
result = SetCursorPos(40, 55) '滑鼠會移到作標X =45 Y=55的位置
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'啟動滑鼠左鍵 按下去又放開
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
'啟動滑鼠右鍵 按下去又放開
mouse_event MOUSEEVENTF_WHEEL, 0, 0, WHEEL_DELTA, 0
'滑鼠中間滾輪往上移
mouse_event MOUSEEVENTF_WHEEL, 0, 0, WHEEL_DELTA, 0
'滑鼠中間滾輪往上移
SendKeys "^c" 'Ctrl+C 複製 Copy
SendKeys "^v" 'Ctrl+V 貼上 Post
SendKeys "^s" 'Ctrl+S 儲存 Save
SendKeys "^v" 'Ctrl+V 貼上 Post
SendKeys "^s" 'Ctrl+S 儲存 Save
接下來是拖曳部分:很簡單的說因為拖曳的理念是
點滑鼠左鍵不放,然後移動到一定的位置,再放開
例如:(滑鼠拖曳範例)
Dim result As Boolean
result = SetCursorPos(2, 55)
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
result = SetCursorPos(3, 198)
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
沒有留言:
張貼留言