Verschiedene Mausroutinen,
zum Beispiel das Bewegen an eine bestimmte Stelle,
x- und y-Koordinaten ermitteln und Mausklicks simulieren:
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 Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
'Mausposition X ermitteln
Public Function Maus_X() As Long
Dim n As POINTAPI
GetCursorPos n
Maus_X = n.x
End Function
'Mausposition Y ermitteln
Public Function Maus_Y() As Long
Dim n As POINTAPI
GetCursorPos n
Maus_Y = n.y
End Function
'Linke Maustaste simulieren
Public Sub LinksKlick()
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
End Sub
'Mittlerer Maustaste simulieren
Public Sub MiddleClick()
mouse_event &H20, 0, 0, 0, 0
mouse_event &H40, 0, 0, 0, 0
End Sub
'Rechte Maustaste simulieren
Public Sub RechtsKlick()
mouse_event &H8, 0, 0, 0, 0
mouse_event &H10, 0, 0, 0, 0
End Sub
'Maus nach x,y bewegen
Public Sub MausBewegen(x As Long, y As Long)
SetCursorPos x, y
End Sub
Eine oft gestellte Frage:
Mausklicks systemweit abfangen:
Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
If GetAsyncKeyState(&H1) Then ... 'links
If GetAsyncKeyState(&H2) Then ... 'rechts
Und hier noch ein
kleiner "Gag",
kreisförmiges Bewegen des
Mauszeigers:
Private Sub DegreesToXY(CenterX As Long, CenterY As Long, _
Winkel As Double, RadiusX As Long, RadiusY As Long)
Dim convert As Double
Dim x As Long
Dim y As Long
convert = 3.141593 / 180
x = CenterX - (Sin(-Winkel * convert) * RadiusX)
y = CenterY - (Sin((90 + (Winkel)) * convert) * RadiusY)
MausBewegen x, y
Sleep 0.009
End Sub
Private Sub Sleep(Sekunden As Double)
Dim tmp As Double
tmp = Timer
Do While Timer - tmp < Sekunden
DoEvents
If Timer < tmp Then tmp = tmp - 24# * 3600#
Loop
End Sub
Public Sub Kreisbewegung()
Dim Winkel As Double
For Winkel = 0 To 360
DegreesToXY Screen.Width / 15 / 2, Screen.Height / 15 / 2, _
Winkel, 200, 200
Next Winkel
End Sub
Hier noch eine kleine, nette Routine:
Systemweit den aktuellen Mauszeiger abfragen:
|