Public Class FrmCapture Private _currentActionPointsList As New List(Of Tuple(Of Integer, Integer))() 'List array of x/y points for the current mouse action being created Private _lastActionPoint As Tuple(Of Integer, Integer) 'The last x/y point that was taken Private _penColor As New Pen(Color.Black, 2) 'Default pen color for the graphics drawing to use Private _graphics As Drawing.Graphics 'Loading the graphics interface Private _selectedKey As Char 'The selected key character for this command Private _offsetX As Integer 'The mouse offset for X so that we can reset the actions x/y to 0 later Private _offsetY As Integer 'The mouse offset for Y so that we can reset the actions x/y to 0 later Private _pollingTicked As Boolean 'Polling tick for the mouse since mice today are like 5 million dpi and we dont need that much info Private Sub FrmCapture_Load(sender As Object, e As EventArgs) Handles MyBase.Load _graphics = Me.CreateGraphics() _selectedKey = Nothing _pollingTicked = True _offsetX = 0 _offsetY = 0 End Sub Private Sub FrmCapture_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown 'Method to clear the current action if the user tries to redraw it _currentActionPointsList.Clear() _graphics.Clear(FrmCapture.DefaultBackColor) End Sub Private Sub FrmCapture_Closed(sender As Object, e As EventArgs) Handles Me.Closed If _selectedKey <> Nothing Then 'Check if the user has selected a key to use for the action otherwise just close the form with no save Dim name As String = InputBox("Please give this action a name", "Name?", "No Name") 'Ask the user to select a name If name.Trim = "" Then name = "No Name" End If 'Add the action to the actions list on the main form FrmMain.ChkActions.Items.Add(name & " | " & _selectedKey) FrmMain.mouseActionList.Add(_selectedKey, _currentActionPointsList) End If End Sub Private Sub FrmCapture_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown 'Method to listen for a keypress to set the actions key value Dim selectedChar As Char = Chr(e.KeyValue) If e.KeyCode = Keys.Escape Then 'If escape is hit then close the form Me.Close() ElseIf Char.IsLetter(selectedChar) Or Char.IsNumber(selectedChar) Then 'Check if its a letter or number input If Not FrmMain.mouseActionList.ContainsKey(selectedChar) Then ' Check if the key is already in the actions array _selectedKey = Chr(e.KeyValue) LblKeySet.Text = Chr(e.KeyValue) Else MsgBox("That key is already taken", MsgBoxStyle.Critical, "Taken!") End If End If End Sub Private Sub FrmCapture_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove 'Method to listen for mouse movements and to draw the action when the left button is clicked If e.Button = Windows.Forms.MouseButtons.Left Then 'Wait for the left button to be held down If _pollingTicked Then 'Check if the timer has ticked If _currentActionPointsList.Count > 0 Then 'If the action has already started recording then draw the connecting line _graphics.DrawLine(_penColor, (_lastActionPoint.Item1 - Me.Location.X), (_lastActionPoint.Item2 - Me.Location.Y), (Cursor.Position.X - Me.Location.X), (Cursor.Position.Y - Me.Location.Y)) Else 'Otherwise set the initial offset values so that we can reset them to 0 and make them relative _offsetX = Cursor.Position.X _offsetY = Cursor.Position.Y End If 'Add the current X and Y to the list and set the "last" value _currentActionPointsList.Add(Tuple.Create(Cursor.Position.X - _offsetX, Cursor.Position.Y - _offsetY)) _lastActionPoint = Tuple.Create(Cursor.Position.X, Cursor.Position.Y) _pollingTicked = False End If End If End Sub Private Sub MovePoleTick_Tick(sender As Object, e As EventArgs) Handles MovePoleTick.Tick 'Method for when the timer has ticked to reset the polling and allow input _pollingTicked = True End Sub End Class