From a2ad5443d5539b438ade7a2cde523bf0beb2b9a5 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Thu, 29 Sep 2022 00:06:54 +0100 Subject: [PATCH] Added some faux mouse polling since the movements were creating way too many events (this wasn't an issue in the past with low DPI mice) Added a check to make sure the user cannot use the same Key twice for actions Added a count down timer update for when a user is setting the start position so they know how long they need to wait Added an offset to the final click in the action so the mouse re-clicks the app window into focus Removed some unused code and Cleaned up some methods --- GoogleGameThing.sln | 19 +++++- GoogleGameThing/FrmCapture.Designer.vb | 14 +++- GoogleGameThing/FrmCapture.resx | 3 + GoogleGameThing/FrmCapture.vb | 37 +++++++--- GoogleGameThing/FrmMain.Designer.vb | 22 +++--- GoogleGameThing/FrmMain.resx | 3 + GoogleGameThing/FrmMain.vb | 25 +++++-- GoogleGameThing/GoogleGameThing.vbproj | 78 ++++++++++++++++++++++ GoogleGameThing/My Project/AssemblyInfo.vb | 12 ++-- README.md | 2 +- 10 files changed, 177 insertions(+), 38 deletions(-) diff --git a/GoogleGameThing.sln b/GoogleGameThing.sln index d0075e0..97f4452 100644 --- a/GoogleGameThing.sln +++ b/GoogleGameThing.sln @@ -1,22 +1,37 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GoogleGameThing", "GoogleGameThing\GoogleGameThing.vbproj", "{E8891FA6-F0A6-4CD0-A7F5-70E384401321}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|x64.ActiveCfg = Debug|x64 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|x64.Build.0 = Debug|x64 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|x86.ActiveCfg = Debug|x86 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Debug|x86.Build.0 = Debug|x86 {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|Any CPU.Build.0 = Release|Any CPU + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|x64.ActiveCfg = Release|x64 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|x64.Build.0 = Release|x64 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|x86.ActiveCfg = Release|x86 + {E8891FA6-F0A6-4CD0-A7F5-70E384401321}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ED36CB52-55FE-4438-B35E-B90C0140E935} + EndGlobalSection EndGlobal diff --git a/GoogleGameThing/FrmCapture.Designer.vb b/GoogleGameThing/FrmCapture.Designer.vb index 5317d6a..3a3de49 100644 --- a/GoogleGameThing/FrmCapture.Designer.vb +++ b/GoogleGameThing/FrmCapture.Designer.vb @@ -1,9 +1,9 @@ - _ + Partial Class FrmCapture Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. - _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then @@ -20,12 +20,14 @@ Partial Class FrmCapture 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. - _ + Private Sub InitializeComponent() + Me.components = New System.ComponentModel.Container() Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.Label3 = New System.Windows.Forms.Label() Me.LblKeySet = New System.Windows.Forms.Label() + Me.MovePoleTick = New System.Windows.Forms.Timer(Me.components) Me.SuspendLayout() ' 'Label1 @@ -63,6 +65,11 @@ Partial Class FrmCapture Me.LblKeySet.Size = New System.Drawing.Size(0, 13) Me.LblKeySet.TabIndex = 3 ' + 'MovePoleTick + ' + Me.MovePoleTick.Enabled = True + Me.MovePoleTick.Interval = 1 + ' 'FrmCapture ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -84,4 +91,5 @@ Partial Class FrmCapture Friend WithEvents Label2 As Label Friend WithEvents Label3 As Label Friend WithEvents LblKeySet As Label + Friend WithEvents MovePoleTick As Timer End Class diff --git a/GoogleGameThing/FrmCapture.resx b/GoogleGameThing/FrmCapture.resx index 1af7de1..0321919 100644 --- a/GoogleGameThing/FrmCapture.resx +++ b/GoogleGameThing/FrmCapture.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/GoogleGameThing/FrmCapture.vb b/GoogleGameThing/FrmCapture.vb index fcaab85..8ce2349 100644 --- a/GoogleGameThing/FrmCapture.vb +++ b/GoogleGameThing/FrmCapture.vb @@ -7,9 +7,12 @@ 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 @@ -32,25 +35,37 @@ 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(Chr(e.KeyValue)) Or Char.IsNumber(Chr(e.KeyValue)) Then 'Check if its a letter or number input - _selectedKey = Chr(e.KeyValue) - LblKeySet.Text = Chr(e.KeyValue) + 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 _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 + 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 - '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) 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 \ No newline at end of file diff --git a/GoogleGameThing/FrmMain.Designer.vb b/GoogleGameThing/FrmMain.Designer.vb index c8a4721..dc712d8 100644 --- a/GoogleGameThing/FrmMain.Designer.vb +++ b/GoogleGameThing/FrmMain.Designer.vb @@ -24,6 +24,7 @@ Partial Class FrmMain Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Me.GroupBox1 = New System.Windows.Forms.GroupBox() + Me.TxtCap = New System.Windows.Forms.TextBox() Me.CmdPos = New System.Windows.Forms.Button() Me.lblMousePos = New System.Windows.Forms.Label() Me.LblLastInput = New System.Windows.Forms.Label() @@ -34,7 +35,7 @@ Partial Class FrmMain Me.CmdRecAct = New System.Windows.Forms.Button() Me.PlayTime = New System.Windows.Forms.Timer(Me.components) Me.PosSel = New System.Windows.Forms.Timer(Me.components) - Me.TxtCap = New System.Windows.Forms.TextBox() + Me.PosCountDown = New System.Windows.Forms.Timer(Me.components) Me.GroupBox1.SuspendLayout() Me.SuspendLayout() ' @@ -59,6 +60,14 @@ Partial Class FrmMain Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Tools" ' + 'TxtCap + ' + Me.TxtCap.Location = New System.Drawing.Point(219, 308) + Me.TxtCap.Name = "TxtCap" + Me.TxtCap.Size = New System.Drawing.Size(10, 20) + Me.TxtCap.TabIndex = 12 + Me.TxtCap.Visible = False + ' 'CmdPos ' Me.CmdPos.Location = New System.Drawing.Point(3, 464) @@ -83,7 +92,7 @@ Partial Class FrmMain Me.LblLastInput.Font = New System.Drawing.Font("Microsoft Sans Serif", 50.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblLastInput.Location = New System.Drawing.Point(80, 368) Me.LblLastInput.Name = "LblLastInput" - Me.LblLastInput.Size = New System.Drawing.Size(73, 76) + Me.LblLastInput.Size = New System.Drawing.Size(72, 76) Me.LblLastInput.TabIndex = 9 Me.LblLastInput.Text = "[]" ' @@ -141,14 +150,6 @@ Partial Class FrmMain ' Me.PosSel.Interval = 5000 ' - 'TxtCap - ' - Me.TxtCap.Location = New System.Drawing.Point(219, 308) - Me.TxtCap.Name = "TxtCap" - Me.TxtCap.Size = New System.Drawing.Size(10, 20) - Me.TxtCap.TabIndex = 12 - Me.TxtCap.Visible = False - ' 'FrmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) @@ -176,4 +177,5 @@ Partial Class FrmMain Friend WithEvents CmdPos As Button Friend WithEvents PosSel As Timer Friend WithEvents TxtCap As TextBox + Friend WithEvents PosCountDown As Timer End Class diff --git a/GoogleGameThing/FrmMain.resx b/GoogleGameThing/FrmMain.resx index f4d0920..5c7c592 100644 --- a/GoogleGameThing/FrmMain.resx +++ b/GoogleGameThing/FrmMain.resx @@ -123,4 +123,7 @@ 117, 17 + + 204, 17 + \ No newline at end of file diff --git a/GoogleGameThing/FrmMain.vb b/GoogleGameThing/FrmMain.vb index ed27ac6..8713600 100644 --- a/GoogleGameThing/FrmMain.vb +++ b/GoogleGameThing/FrmMain.vb @@ -4,6 +4,10 @@ Public mouseActionStartPosition As Tuple(Of Integer, Integer) 'The start x and y location on the screen for the mouse action to move from Private _mouseStartPositionSet As Boolean 'Bool to check if the user has set the start mouse position yet or not + 'Ints to store a couple of tick values we can use to compare + Private _posSetStartTick As Integer + Private _posSetCurrentTick As Integer + Private Sub CmdExit_Click(sender As Object, e As EventArgs) Handles CmdExit.Click 'Quit the app Me.Close() @@ -12,11 +16,10 @@ Private Sub CmdRecAct_Click(sender As Object, e As EventArgs) Handles CmdRecAct.Click Dim capFrm As New FrmCapture capFrm.Location = New Point(Me.Location.X - capFrm.Width, Me.Location.Y) - capFrm.ShowDialog() End Sub - Private Sub CmdRemSel_Click(sender As Object, e As EventArgs) Handles CmdRemSel.Click 'Method for removing mouse actions from the action list + Private Sub CmdRemSel_Click(sender As Object, e As EventArgs) Handles CmdRemSel.Click 'Method for removing mouse actions from the action list1 Dim sel_text As String() = ChkActions.SelectedItem.ToString.Split(" | ") ChkActions.Items.RemoveAt(ChkActions.SelectedIndex) @@ -39,7 +42,7 @@ mouse_event(&H4&, 0, 0, 0, 0) 'Release the left click 'Set the mouse location back to the app and click to try get focus, click and release the button incase it stuck for some reason, force focus and bring to the front - Cursor.Position = New Point(Me.Location.X, Me.Location.Y) + Cursor.Position = New Point(Me.Location.X + 10, Me.Location.Y + 10) 'Needs offset! mouse_event(&H2&, 0, 0, 0, 0) mouse_event(&H4&, 0, 0, 0, 0) @@ -56,7 +59,10 @@ End Sub Private Sub CmdPos_Click(sender As Object, e As EventArgs) Handles CmdPos.Click - PosSel.Enabled = True 'Start the timer to listen for the start moust position method + _posSetStartTick = Environment.TickCount 'Get the enviroment time we can use to get the amount of milliseconds between 2 points in the app + _posSetCurrentTick = Environment.TickCount + PosSel.Start() 'Start the timer to listen for the start moust position method + PosCountDown.Start() CmdPos.BackColor = Color.Green End Sub @@ -65,7 +71,16 @@ lblMousePos.Text = "Mouse Pos: " & Cursor.Position.X & ":" & Cursor.Position.Y CmdPos.BackColor = Color.Red _mouseStartPositionSet = True - PosSel.Enabled = False + PosCountDown.Stop() + PosSel.Stop() End Sub + Private Sub PosCountDown_Tick(sender As Object, e As EventArgs) Handles PosCountDown.Tick 'Method to update the pos label with a timer to show the user when the position has been taken + If PosSel.Enabled Then 'Check if the pos timer is currently running + _posSetCurrentTick = Environment.TickCount 'Get the current enviroment time to check how many millisecs have passed + Dim currentTimeElapsed As Integer = (PosSel.Interval - (_posSetCurrentTick - _posSetStartTick)) / 1000 'Get the time passed in seconds and count down from the inteval + + lblMousePos.Text = "Pos Capture in: " & currentTimeElapsed.ToString() + End If + End Sub End Class diff --git a/GoogleGameThing/GoogleGameThing.vbproj b/GoogleGameThing/GoogleGameThing.vbproj index 79609c9..c4037d6 100644 --- a/GoogleGameThing/GoogleGameThing.vbproj +++ b/GoogleGameThing/GoogleGameThing.vbproj @@ -13,6 +13,21 @@ WindowsForms v4.6.1 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -52,6 +67,57 @@ AppIcon.ico + + true + true + true + bin\x86\Debug\ + GoogleGameThing.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + full + x86 + true + + + true + bin\x86\Release\ + GoogleGameThing.xml + true + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + pdbonly + x86 + true + + + true + true + true + bin\x64\Debug\ + GoogleGameThing.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + full + x64 + true + + + true + bin\x64\Release\ + GoogleGameThing.xml + true + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + pdbonly + x64 + true + + + bin\Release32\ + + + bin\x86\Release32\ + + + bin\x64\Release32\ + @@ -138,6 +204,18 @@ + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + +