Tema: FAQ's de VB6
Ver Mensaje Individual
  #54 (permalink)  
Antiguo 06/04/2005, 17:33
Avatar de vbx3m
vbx3m
 
Fecha de Ingreso: febrero-2005
Ubicación: Venezuela
Mensajes: 524
Antigüedad: 19 años, 10 meses
Puntos: 1
Autoclick

Agregas un modulo de clase y lo llamas clsmouse y copias:
Código:
Option Explicit
Public Event PositionChanged()
Public Event SytemClick(ByVal Button As MouseButtonConstants)
Private Const VK_RBUTTON As Long = &H2
Private Const VK_MBUTTON As Long = &H4
Private Const VK_LBUTTON As Long = &H1
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Private Const MOUSEEVENTF_MIDDLEDOWN As Long = &H20
Private Const MOUSEEVENTF_MIDDLEUP As Long = &H40
Private Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Private Const MOUSEEVENTF_RIGHTUP As Long = &H10
Private Type POINTAPI
X As Long
Y As Long
End Type
Private m_WatchPosition As Boolean
Private m_WatchSystemClicks As Boolean
Private m_Position As New clsmouseposition
Private Declare Function GetCursorPos Lib "user32" (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)

Public Sub Click(Optional MouseButton As MouseButtonConstants = vbLeftButton)
If (MouseButton = vbLeftButton) Then
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&)
ElseIf (MouseButton = vbMiddleButton) Then
Call mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0&, 0&, 0&, 0&)
Call mouse_event(MOUSEEVENTF_MIDDLEUP, 0&, 0&, 0&, 0&)
ElseIf (MouseButton = vbRightButton) Then
Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0&, 0&, 0&, 0&)
Call mouse_event(MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&)
End If
End Sub

Private Function CompKey(KCode As Long) As Boolean
Dim Result As Long
Result = GetAsyncKeyState(KCode)
If Result = -32767 Then
CompKey = True
Else
CompKey = False
End If
End Function

Public Property Get Position() As clsmouseposition
Set Position = m_Position
End Property

Public Property Let TimerEvent(ByVal Dummmy As Boolean)
Dim CurPos As POINTAPI
Dim Value As MouseButtonConstants
Static First As Boolean
Static mx As Long
Static my As Long
If m_WatchPosition Then
Call GetCursorPos(CurPos)
If First Then
If CurPos.X <> mx Or CurPos.Y <> my Then
RaiseEvent PositionChanged
End If
End If
mx = CurPos.X
my = CurPos.Y
End If
If m_WatchSystemClicks Then
If CompKey(VK_LBUTTON) Then
Value = vbLeftButton
End If
If CompKey(VK_RBUTTON) Then
Value = Value Or vbRightButton
End If
If CompKey(VK_MBUTTON) Then
Value = Value Or vbMiddleButton
End If
If Value <> 0 Then
RaiseEvent SytemClick(Value)
End If
End If
First = True
End Property
Agregas otro y lo llamas clsmouseposition y pegas:

Código:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private m_x As Long
Private m_y 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 Sub GetPosition()
Dim P As POINTAPI
Call GetCursorPos(P)
m_y = P.Y
m_x = P.X
End Sub

Public Property Get X() As Long
Call GetPosition
X = m_x
End Property

Public Property Let X(lngValue As Long)
Call SetCursorPos(lngValue, m_y)
m_x = lngValue
End Property

Public Property Get Y() As Long
Call GetPosition
Y = m_y
End Property

Public Property Let Y(lngValue As Long)
Call SetCursorPos(m_x, lngValue)
m_y = lngValue
End Property
y en el form pones:
Código:
Option Explicit
Private WithEvents Mouse As clsmouse

Private Sub Command1_Click()
With Mouse
.Position.X = coodenada 
.Position.Y = coordenada 
.Click (vbLeftButton)
End With
'Si quieres pones x=100 y y=100, pones el Startupposition en center screen y que tu form no ocupe la pantalla completa hazlo pequeño para que veas que pasa
End Sub

Private Sub Form_Load()
Set Mouse = New clsmouse
End Sub
Espero les sirva...
__________________
ホルヘ・ラファエル・マルティネス・レオン

Última edición por vbx3m; 10/05/2006 a las 12:26