' 撰寫人:Devil(璉璉) E-Mail: qvb3377@ms5.hinet.net 僅供學術測試使用,引用請註明原出處 ' -------------------------------------------------------------------------------------- Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As enuMOUSEEVENTF, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function GetCapture Lib "user32" () As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long) As Long Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, ByVal crColor As Long) As Long Private Type POINTAPI X As Long Y As Long End Type Public Enum enuMouseButton MB_Left = &H2 MB_Right = &H8 MB_Middle = &H20 End Enum Private Enum enuMouseAction MA_MouseDown = 1 MA_MouseUp = 2 MA_MouseClick = MA_MouseDown + MA_MouseUp End Enum Private Enum enuMOUSEEVENTF MOUSEEVENTF_MOVE = &H1 ' mouse move MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move MOUSEEVENTF_LEFTDOWN = MB_Left * MA_MouseDown ' left button down MOUSEEVENTF_LEFTUP = MB_Left * MA_MouseUp ' left button up MOUSEEVENTF_LEFTClick = MB_Left * MA_MouseClick ' left button Click MOUSEEVENTF_RIGHTDOWN = MB_Right * MA_MouseDown ' right button down MOUSEEVENTF_RIGHTUP = MB_Right * MA_MouseUp ' right button up MOUSEEVENTF_RIGHTClick = MB_Right * MA_MouseClick ' right button Click MOUSEEVENTF_MIDDLEDOWN = MB_Middle * MA_MouseDown ' middle button down MOUSEEVENTF_MIDDLEUP = MB_Middle * MA_MouseUp ' middle button up MOUSEEVENTF_MIDDLEClick = MB_Middle * MA_MouseClick ' middle button Click End Enum Public dwData As Long, dwExtraInfo As Long Private dx As Long, dy As Long Private m_x As Long, m_y As Long Public Property Get Pixel() As Long Pixel = GetPixel(hDC, X, Y) End Property Public Property Let Pixel(ByVal vColor As Long) SetPixel hDC, X, Y, vColor End Property Public Property Get hDC() As Long hDC = GetWindowDC(hWnd) End Property Public Property Get hWnd() As Long MouseGetCursorPos hWnd = WindowFromPoint(m_x, m_y) End Property Public Property Get X() As Variant MouseGetCursorPos X = m_x End Property Public Property Get Y() As Variant MouseGetCursorPos Y = m_y End Property Public Property Let X(ByVal xPos As Variant) m_x = xPos MouseSetCursorPos End Property Public Property Let Y(ByVal yPos As Variant) m_y = yPos MouseSetCursorPos End Property Private Sub MouseSetCursorPos() summy = SetCursorPos(m_x, m_y) End Sub Private Sub MouseGetCursorPos() Dim lpPoint As POINTAPI summy = GetCursorPos(lpPoint) m_x = lpPoint.X m_y = lpPoint.Y End Sub Private Sub MouseAction(ByVal MouseButton As enuMouseButton, ByVal bHere As Boolean) If bHere Then dx = 0 dy = 0 mouse_event MouseButton, dx, dy, dwData, dwExtraInfo Else MouseButton = MouseButton Or MOUSEEVENTF_ABSOLUTE mouse_event MouseButton, X, Y, dwData, dwExtraInfo End If End Sub Public Sub Drag(Optional ByVal bHere As Boolean = True) ButtonDown MB_Left, bHere End Sub Public Sub Drop(Optional ByVal bHere As Boolean = True) ButtonUp MB_Left, bHere End Sub Public Sub Click(Optional ByVal MouseButton As enuMouseButton = MB_Left, Optional ByVal bHere As Boolean = True) iClick = MouseButton * MA_MouseClick MouseAction iClick, bHere End Sub Public Sub DblClick(Optional ByVal MouseButton As enuMouseButton = MB_Left, Optional ByVal bHere As Boolean = True) For i = 1 To 2 Click MouseButton, bHere Next End Sub Public Sub ButtonDown(Optional ByVal MouseButton As enuMouseButton = MB_Left, Optional ByVal bHere As Boolean = True) iDown = MouseButton MouseAction iDown, bHere End Sub Public Sub ButtonUp(Optional ByVal MouseButton As enuMouseButton = MB_Left, Optional ByVal bHere As Boolean = True) iUp = MouseButton * MA_MouseUp MouseAction iUp, bHere End Sub