Postada em 13/10/2008 12:20 hs
Ele posiciona certo, mas não clica o botão esquerdo. Por que ?
Abaixo esta o codigo :
' reconhece qual botão foi clicado e seu estado Down ou UP Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
' checa posição mouse e gera um clique/eventos no mouse Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) 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_MOVE = &H1 ' mouse move Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down Private Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up Private Const MOUSEEVENTF_WHEEL = &H800 ' wheel button rolled Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Private Type POINTAPI X As Long Y As Long End Type
Dim pt As POINTAPI Dim pts As POINTAPI Dim cur_x As Single Dim cur_y As Single Dim dest_x As Single Dim dest_y As Single
Private Sub Timer1_Timer() If GetAsyncKeyState(2) = 0 Then ' clicou botão esquerdo e não faz nada Else ' clicou botão direito ' Things are easier working in pixels. Me.ScaleMode = vbPixels ' mouse_event moves in a coordinate system where ' (0, 0) is in the upper left corner and ' (65535,65535) is in the lower right corner. ' Get the current mouse coordinates and convert them into this new ' system.GetCursorPos pt cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels) cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels) ' Salva as coordenadas do mouse (NOVO) pts.X = cur_x pts.Y = cur_y
' Convert the coordinates of the center of the form into this new ' system. pt.X = Me.ScaleLeft pt.Y = Me.ScaleTop
'pt.X = Me.ScaleWidth / 2 'pt.Y = Me.ScaleHeight / 2 ClientToScreen Me.hwnd, pt dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, vbPixels) dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, vbPixels) ' Move the mouse to its final destination and click it. mouse_event _ MOUSEEVENTF_ABSOLUTE + _ MOUSEEVENTF_MOVE + _ MOUSEEVENTF_LEFTDOWN + _ MOUSEEVENTF_LEFTUP, 17000, 13000, 0, 0 mouse_event MOUSEEVENTF_LEFTDOWN, 17000, 13000, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, 17000, 13000, 0, 0
' move o mouse para a posição inicial (NOVO) ' mouse_event _ ' MOUSEEVENTF_ABSOLUTE + _ ' MOUSEEVENTF_MOVE, _ ' pts.X, pts.Y, 0, 0 End If End Sub
|