Imports System.Windows.Forms
Public Class Form1
#Region "API"
Declare Auto Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As IntPtr)
Declare Auto Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As Int16
Public Enum MouseEventTFlags
LEFTDOWN = 2
LEFTUP = 4
MIDDLEDOWN = 32
MIDDLEUP = 64
MOVE = 1
ABSOLUTE = 0
RIGHTDOWN = 8
RIGHTUP = 16
End Enum
#End Region
Public RecordingFile As IO.StreamWriter
Public Mov As New ArrayList
Public MovIndex As UInt32
Private Sub tmrTrackMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTrackMouse.Tick
Dim Pos As Point = Cursor.Position
'False = mouse up; True = mouse down
Dim LClick As Boolean = GetAsyncKeyState(Keys.LButton)
'Dim RClick As Boolean = GetAsyncKeyState(Keys.RButton)
'Dim MClick As Boolean = GetAsyncKeyState(Keys.MButton)
RecordingFile.Write(Pos.X & ":" & Pos.Y & ":" & CInt(LClick) & ";") '":" & CInt(RClick) & ":" & CInt(MClick) & ";")
End Sub
Private Sub cmdRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRecord.Click
If cmdRecord.Text = "Registra i movimenti del mouse" Then
Dim S As New SaveFileDialog
S.Filter = "Movimenti del mouse|*.mmov"
If S.ShowDialog = Windows.Forms.DialogResult.OK Then
RecordingFile = New IO.StreamWriter(S.FileName)
tmrTrackMouse.Start()
End If
cmdRecord.Text = "Termina"
Else
tmrTrackMouse.Stop()
RecordingFile.Close()
cmdRecord.Text = "Registra i movimenti del mouse"
End If
End Sub
Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click
Dim O As New OpenFileDialog
O.Filter = "Movimenti del mouse|*.mmov"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim R As New IO.StreamReader(O.FileName)
Dim S As String = R.ReadToEnd
R.Close()
Dim Data() As String = S.Split(";")
Mov.Clear()
For V As UInt16 = 0 To Data.Length - 2
If V <> Nothing Then
Mov.Add(Data(V))
End If
Next
MovIndex = 0
tmrPlay.Start()
End If
End Sub
Private Sub tmrPlay_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPlay.Tick
Dim Values() As String = Mov(MovIndex).Split(":")
Dim X As Int32 = CInt(Values(0))
Dim Y As Int32 = CInt(Values(1))
Dim LClick As Boolean = CBool(Values(2))
'Dim RClick As Boolean = CBool(Values(3))
'Dim MClick As Boolean = CBool(Values(4))
Cursor.Position = New Point(X, Y)
If LClick Then
mouse_event(2, 0, 0, 0, 0)
Else
mouse_event(4, 0, 0, 0, 0)
End If
'If RClick Then
'mouse_event(8, 0, 0, 0, 0)
'Else
'mouse_event(16, 0, 0, 0, 0)
'End If
'If MClick Then
'mouse_event(32, 0, 0, 0, 0)
'Else
'mouse_event(64, 0, 0, 0, 0)
'End If
If MovIndex < Mov.Count - 1 Then
MovIndex += 1
Else
tmrPlay.Stop()
MsgBox("Movimenti eseguiti!", MsgBoxStyle.Information)
MovIndex = 0
End If
End Sub
Private Sub nudInterval_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudInterval.ValueChanged
tmrTrackMouse.Interval = nudInterval.Value
tmrPlay.Interval = nudInterval.Value
End Sub
End Class