Simulation Mousclick mit VB 2008

#1337861
Lesenswert?

Hab mal hir eine Klasse für dich
1
 Public Class Class1
2
    Public Enum MouseEvent
3
        Move = 1
4
        LeftDown = 2
5
        LeftUp = 4
6
        RightDown = 8
7
        RightUp = 16
8
        MiddleDown = 32
9
        MiddleUp = 64
10
        XDown = 128
11
        XUp = 256
12
        Wheel = 2048
13
    End Enum
14

15
    Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As MouseEvent, ByVal dx As Integer, ByVal dy As Integer, ByVal dwdata As Integer, ByVal dwExtraInfo As Integer)
16

17
    Public Shared Sub Click(ByVal MouseEvent As MouseEvent, ByVal Location As Point, Optional ByVal Absolute As Boolean = True)
18
        Dim pt As Point = Windows.Forms.Cursor.Position 'Position des Cursors speichern
19
        Windows.Forms.Cursor.Position = Location
20
        Dim x As Integer = Location.X * 65535 / Screen.PrimaryScreen.Bounds.Width
21
        Dim y As Integer = Location.Y * 65535 / Screen.PrimaryScreen.Bounds.Height
22
        If Absolute = True Then
23
            mouse_event(MouseEvent Or 32768, x, y, 0, 0)
24
        Else
25
            mouse_event(MouseEvent, x, y, 0, 0)
26
        End If
27
        Windows.Forms.Cursor.Position = pt
28
    End Sub
29
End Class

Und ein kleines Beispiel:
1
Class1.Click(Class1.MouseEvent.LeftDown, New Point(MousePosition.X, MousePosition.Y))
2
Class1.Click(Class1.MouseEvent.LeftUp, New Point(MousePosition.X, MousePosition.Y))
 Simuliert einen klick auf die aktuelle Mausposition

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren