'vb.net 模擬滑鼠點下
Option Explicit On
Module MManip
'API 定義
Public Declare Sub Mouse_Event Lib "user32" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32)
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Int32, ByVal Y As Int32) As Int32
Public Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Int32
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MOVE = &H1
Public Structure POINTAPI
Dim X As Int32
Dim Y As Int32
End Structure
'取得目前滑鼠座標
Public Function GetCurrentPos() As POINTAPI
Dim Position As POINTAPI
GetCursorPos(Position)
GetCurrentPos = Position
End Function
'取得目前滑鼠座標 x 值
Public Function GetCurrentX() As int32
Dim Position As POINTAPI
GetCursorPos(Position)
GetCurrentX = Position.X
End Function
'取得目前滑鼠座標 y 值
Public Function GetCurrentY() As int32
Dim Position As POINTAPI
GetCursorPos(Position)
GetCurrentY = Position.Y
End Function
'滑鼠左擊
Public Sub LeftClick()
LeftDown()
LeftUp()
End Sub
'按下滑鼠左鍵
Public Sub LeftDown()
Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub
'放開滑鼠左鍵
Public Sub LeftUp()
Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
'滑鼠中擊
Public Sub MiddleClick()
MiddleDown()
MiddleUp()
End Sub
'按下滑鼠中鍵
Public Sub MiddleDown()
Mouse_Event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
End Sub
'放開滑鼠中鍵
Public Sub MiddleUp()
Mouse_Event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
End Sub
'移動滑鼠
Public Sub MoveMouse(ByVal xMove As int32, ByVal yMove As int32)
Mouse_Event(MOUSEEVENTF_MOVE, xMove, yMove, 0, 0)
End Sub
'滑鼠右擊
Public Sub RightClick()
RightDown()
RightUp()
End Sub
'按下滑鼠右鍵
Public Sub RightDown()
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
End Sub
'放開滑鼠右鍵
Public Sub RightUp()
Mouse_Event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
End Sub
End Module
- Nov 05 Sat 2011 13:34
[VB.NET] 模擬滑鼠功能
全站熱搜
留言列表
發表留言