红阳网站
扫描关注红阳网站

微信扫描

VB.NET控制鼠标模拟移动及单击

红阳网站2017-02-05VB.NET 13610 0A+A-

控制鼠标,模拟鼠标移动到屏幕上的指定点并点击 

 

Imports System.Runtime.InteropServices

 

<DllImport("user32.dll")> _
    Private Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Private Shared Sub mouse_event(ByVal flags As MouseEventFlag, ByVal dx As Integer, ByVal dy As Integer, ByVal data As UInteger, ByVal extraInfo As UIntPtr)
    End Sub

    <Flags()> _
    Private Enum MouseEventFlag As UInteger
        Move = &H1
        LeftDown = &H2
        LeftUp = &H4
        RightDown = &H8
        RightUp = &H10
        MiddleDown = &H20
        MiddleUp = &H40
        XDown = &H80
        XUp = &H100
        Wheel = &H800
        VirtualDesk = &H4000
        Absolute = &H8000
    End Enum

 

 

SetCursorPos(intX, intY)
mouse_event(MouseEventFlag.LeftDown, intX, intY, 0, UIntPtr.Zero)
mouse_event(MouseEventFlag.LeftUp, intX, intY, 0, UIntPtr.Zero)

 

 

 

'===========

Dim btnLocation As Point = button1.Location
Dim screenLocation As Point
screenLocation = PointToScreen(jkbtnLocation

123