Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 录制鼠标中键和滚轮滚动_.net_Vb.net_Mouse_Mouseevent_Mousewheel - Fatal编程技术网

.net 录制鼠标中键和滚轮滚动

.net 录制鼠标中键和滚轮滚动,.net,vb.net,mouse,mouseevent,mousewheel,.net,Vb.net,Mouse,Mouseevent,Mousewheel,我制作了一个类来记录鼠标的动作,例如用鼠标记录一个任务(在这里移动鼠标,然后在那里单击鼠标左键……) 在记录鼠标动作/任务之后,我可以用我制作的线程从类中复制它 我需要的是实现鼠标中键和滚轮滚动,但我不知道如何实现,对我来说使用和理解“GetAsyncKeyState”有点困难,我找不到有关“GetAsyncKeyState中键状态”或滚轮滚动(向下/向上滚动)的信息 #区域“记录鼠标类” “[记录鼠标功能] ' “//作者:ElektroH@cker ' 例如: '录制鼠标。开始录制() '录

我制作了一个类来记录鼠标的动作,例如用鼠标记录一个任务(在这里移动鼠标,然后在那里单击鼠标左键……)

在记录鼠标动作/任务之后,我可以用我制作的线程从类中复制它

我需要的是实现鼠标中键和滚轮滚动,但我不知道如何实现,对我来说使用和理解“GetAsyncKeyState”有点困难,我找不到有关“GetAsyncKeyState中键状态”或滚轮滚动(向下/向上滚动)的信息

#区域“记录鼠标类”
“[记录鼠标功能]
'
“//作者:ElektroH@cker
'
例如:
'录制鼠标。开始录制()
'录制鼠标。停止录制()
'Record\u Mouse.Play():而不是Record\u Mouse.Play\u已完成:Application.DoEvents():结束时
'记录鼠标。鼠标速度=50
公共类记录鼠标
''' 
''设置录制/播放鼠标动作的速度。
''默认值为25。
''' 
公共共享鼠标\u速度为Int64=25
''' 
''获取当前鼠标播放的状态。
''False=鼠标任务仍在播放。
''True=鼠标任务播放完成。
''' 
公共共享播放已完成,布尔值=False
'将存储鼠标坐标的位置:
私有共享协调列表作为新列表(点)
'将存储鼠标单击的位置:
私有共享字典作为新字典(Int64的鼠标按钮)
'记录鼠标的计时器:
Private Shared with Events将计时器记录为新计时器
'按钮单击计数以记录/播放单击:
私有共享单击计数为Int32=0
'线程以复制鼠标操作:
私有共享线程\u MousePlay\u变量为System.Threading.Thread=New Threading.Thread(线程\u MousePlay的地址)
'记录当前鼠标按钮状态的API:
将私有函数GetAsyncKeyState Lib“user32”(ByVal vKey长度)声明为整数
'复制鼠标按钮单击的API:
Private Declare Sub Mouse_Event Lib“User32”别名“Mouse_Event”(ByVal dwFlags作为MouseButton,ByVal dx作为Integer,ByVal dy作为Integer,ByVal dwData作为Integer,ByVal dwExtraInfo作为Integer)
'GetAsyncKeyState按钮状态
私有共享最后单击状态为Int64=-1
私有共享最后一次单击状态为Int64=-1
枚举鼠标按钮
左下=&H2'左按钮(保持)
左上=&H4'左按钮(释放)
右下=&H8'右按钮(保持)
右上=&H10'右按钮(释放)
中键向下=&H20'中键(保持)
中键向上=&H40'中键(释放)
“左”左按钮(按下)
右键(按下)
“中间”中间按钮(按下)
结束枚举
''' 
''开始在屏幕上记录鼠标动作。
''它记录鼠标的位置和左/右按钮的点击。
''' 
公共共享子开始_记录()
播放完成=错误
记录时间间隔=鼠标速度
协调列表。清除():单击字典。清除():单击计数=0
Record_Timer.Start()
端接头
''' 
''停止记录鼠标动作。
''' 
公共共享子站_记录()
记录计时器。停止()
端接头
''' 
''复制鼠标动作。
''' 
公共共享子游戏()
Thread\u MousePlay\u Var=新的Threading.Thread(Thread\u MousePlay的地址)
Thread\u MousePlay\u Var.IsBackground=True
线程\鼠标播放\变量开始()
端接头
'用于存储鼠标操作的过程
私有共享子记录\u Timer\u Tick(发送方作为对象,e作为事件参数)处理记录\u Timer.Tick
Coordenates_List.Add(Control.MousePosition)
如果不是最后一次单击状态左=GetAsyncKeyState(1),则
上次单击状态左=GetAsyncKeyState(1)
如果GetAsyncKeyState(1)=32768,则
单击_Count+=1
协调列表。添加(无)
单击字典。添加(单击计数,鼠标按钮。左下)
ElseIf GetAsyncKeyState(1)=0然后
单击_Count+=1
协调列表。添加(无)
单击字典。添加(单击计数,鼠标按钮。左上)
如果结束
如果结束
如果不是最后一次单击状态\u Right=GetAsyncKeyState(2),则
最后单击状态右=GetAsyncKeyState(2)
如果GetAsyncKeyState(2)=32768,则
单击_Count+=1
协调列表。添加(无)
单击字典。添加(单击计数,鼠标按钮。右下)
ElseIf GetAsyncKeyState(2)=0然后
单击_Count+=1
协调列表。添加(无)
单击字典。添加(单击计数,鼠标按钮。右键向上)
如果结束
如果结束
端接头
'播放鼠标按钮(单击)的过程
专用共享子鼠标单击(ByVal鼠标按钮作为鼠标按钮)
选择大小写鼠标按钮
Case MouseButton.Left:Mouse_事件(MouseButton.Left_Down,0,0,0):Mouse_事件(MouseButton.Left_Up,0,0,0)
Case MouseButton.Right:Mouse_事件(MouseButton.Right_Down,0,0,0):Mouse_事件(MouseButton.Right_Up,0,0,0)
Case MouseButton.Middle:Mouse_事件(MouseButton.Middle_Down,0,0,0):Mouse_事件(MouseButton.Middle_Up,0,0,0)
Case-Else:Mouse_事件(MouseButton,0,0,0)
结束选择
端接头
'用于复制鼠标操作的线程
私有共享子线程_MousePlay()
单击“计数=0”
对于Coordenates_列表中的每个Coordenate
线程。线程。睡眠(鼠标速度)
如果Coordenate=无,则
单击_Count+=1
如果单击计数>1,则鼠标单击(单击字典项(单击计数))
其他的
光标位置=坐标
如果结束
Application.DoEvents()
下一个
播放完成=真
端接头
末级
#末端区域

您可以使用GetAsyncKeyState(4)获取鼠标中键。但是用这种方法你永远不会得到鼠标滚动信息,没有任何方法可以询问滚动按钮的位置。你必须依靠
#Region " Record Mouse Class "

' [ Record Mouse Functions ]
'
' // By Elektro H@cker
'
' Examples :
' Record_Mouse.Start_Record()
' Record_Mouse.Stop_Record()
' Record_Mouse.Play() : While Not Record_Mouse.Play_Is_Completed : Application.DoEvents() : End While
' Record_Mouse.Mouse_Speed = 50

Public Class Record_Mouse

''' <summary>
''' Sets the speed of recording/playing the mouse actions.
''' Default value is 25.
''' </summary>
Public Shared Mouse_Speed As Int64 = 25

''' <summary>
''' Gets the status pf the current mouse play.
''' False = mouse task is still playing.
''' True = Mouse task play is done.
''' </summary>
Public Shared Play_Is_Completed As Boolean = False

' Where the mouse coordenates will be stored:
Private Shared Coordenates_List As New List(Of Point)
' Where the mouse clicks will be stored:
Private Shared Clicks_Dictionary As New Dictionary(Of Int64, MouseButton)
' Timer to record the mouse:
Private Shared WithEvents Record_Timer As New Timer
' Button click count to rec/play clicks:
Private Shared Click_Count As Int32 = 0
' Thread to reproduce the mouse actions:
Private Shared Thread_MousePlay_Var As System.Threading.Thread = New Threading.Thread(AddressOf Thread_MousePlay)
' API to record the current mouse button state:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
' API to reproduce a mouse button click:
Private Declare Sub Mouse_Event Lib "User32" Alias "mouse_event" (ByVal dwFlags As MouseButton, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer)
' GetAsyncKeyState buttons status
Private Shared Last_ClickState_Left As Int64 = -1
Private Shared Last_ClickState_Right As Int64 = -1

Enum MouseButton

    Left_Down = &H2    ' Left button (hold)
    Left_Up = &H4      ' Left button (release)

    Right_Down = &H8   ' Right button (hold)
    Right_Up = &H10    ' Right button (release)

    Middle_Down = &H20 ' Middle button (hold)
    Middle_Up = &H40   ' Middle button (release)

    Left               ' Left   button (press)
    Right              ' Right  button (press)
    Middle             ' Middle button (press)

End Enum

''' <summary>
''' Starts recording the mouse actions over the screen.
''' It records the position of the mouse and left/right button clicks.
''' </summary>
Public Shared Sub Start_Record()
    Play_Is_Completed = False
    Record_Timer.Interval = Mouse_Speed
    Coordenates_List.Clear() : Clicks_Dictionary.Clear() : Click_Count = 0
    Record_Timer.Start()
End Sub

''' <summary>
''' Stop recording the mouse actions.
''' </summary>
Public Shared Sub Stop_Record()
    Record_Timer.Stop()
End Sub

''' <summary>
''' Reproduce the mouse actions.
''' </summary>
Public Shared Sub Play()
    Thread_MousePlay_Var = New Threading.Thread(AddressOf Thread_MousePlay)
    Thread_MousePlay_Var.IsBackground = True
    Thread_MousePlay_Var.Start()
End Sub

' Procedure used to store the mouse actions
Private Shared Sub Record_Timer_Tick(sender As Object, e As EventArgs) Handles Record_Timer.Tick

    Coordenates_List.Add(Control.MousePosition)

    If Not Last_ClickState_Left = GetAsyncKeyState(1) Then
        Last_ClickState_Left = GetAsyncKeyState(1)
        If GetAsyncKeyState(1) = 32768 Then
            Click_Count += 1
            Coordenates_List.Add(Nothing)
            Clicks_Dictionary.Add(Click_Count, MouseButton.Left_Down)
        ElseIf GetAsyncKeyState(1) = 0 Then
            Click_Count += 1
            Coordenates_List.Add(Nothing)
            Clicks_Dictionary.Add(Click_Count, MouseButton.Left_Up)
        End If
    End If

    If Not Last_ClickState_Right = GetAsyncKeyState(2) Then
        Last_ClickState_Right = GetAsyncKeyState(2)
        If GetAsyncKeyState(2) = 32768 Then
            Click_Count += 1
            Coordenates_List.Add(Nothing)
            Clicks_Dictionary.Add(Click_Count, MouseButton.Right_Down)
        ElseIf GetAsyncKeyState(2) = 0 Then
            Click_Count += 1
            Coordenates_List.Add(Nothing)
            Clicks_Dictionary.Add(Click_Count, MouseButton.Right_Up)
        End If
    End If

End Sub

' Procedure to play a mouse button (click)
Private Shared Sub Mouse_Click(ByVal MouseButton As MouseButton)
    Select Case MouseButton
        Case MouseButton.Left : Mouse_Event(MouseButton.Left_Down, 0, 0, 0, 0) : Mouse_Event(MouseButton.Left_Up, 0, 0, 0, 0)
        Case MouseButton.Right : Mouse_Event(MouseButton.Right_Down, 0, 0, 0, 0) : Mouse_Event(MouseButton.Right_Up, 0, 0, 0, 0)
        Case MouseButton.Middle : Mouse_Event(MouseButton.Middle_Down, 0, 0, 0, 0) : Mouse_Event(MouseButton.Middle_Up, 0, 0, 0, 0)
        Case Else : Mouse_Event(MouseButton, 0, 0, 0, 0)
    End Select
End Sub

' Thread used for reproduce the mouse actions
Private Shared Sub Thread_MousePlay()

    Click_Count = 0

    For Each Coordenate In Coordenates_List

        Threading.Thread.Sleep(Mouse_Speed)

        If Coordenate = Nothing Then
            Click_Count += 1
            If Click_Count > 1 Then Mouse_Click(Clicks_Dictionary.Item(Click_Count))
        Else
            Cursor.Position = Coordenate
        End If

        Application.DoEvents()

    Next

    Play_Is_Completed = True

End Sub

End Class

#End Region