Files
google-game-thing/GoogleGameThing/FrmMain.vb
2022-09-27 14:58:48 +01:00

72 lines
3.9 KiB
VB.net

Public Class FrmMain
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer) 'Grab a reference to the mouse even from the user32 lib in windows so that we can get the position
Public mouseActionList As New Dictionary(Of String, List(Of Tuple(Of Integer, Integer)))() 'A public dictionary to hold the mouse action/keypress details
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
Private Sub CmdExit_Click(sender As Object, e As EventArgs) Handles CmdExit.Click 'Quit the app
Me.Close()
End Sub
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
Dim sel_text As String() = ChkActions.SelectedItem.ToString.Split(" | ")
ChkActions.Items.RemoveAt(ChkActions.SelectedIndex)
Dim char_key As Char = sel_text.Last()
mouseActionList.Remove(char_key)
End Sub
Private Sub FrmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown 'Send the mouse action to the mouse lib to execute the command
If _mouseStartPositionSet = True Then 'Check if the start position has been set so we know where to start the action
If mouseActionList.ContainsKey(Chr(e.KeyValue)) Then 'Check if the keypress is actually in the actions list
LblLastInput.Text = Chr(e.KeyValue)
Cursor.Position = New Point(mouseActionStartPosition.Item1, mouseActionStartPosition.Item2) 'set the mouse position to the start
mouse_event(&H2&, 0, 0, 0, 0) 'Send the left click command
'loop through each point in the action array and set the mouse position
For Each lst_item In mouseActionList.Item(Chr(e.KeyValue))
Cursor.Position = New Point(mouseActionStartPosition.Item1 + lst_item.Item1, mouseActionStartPosition.Item2 + lst_item.Item2)
Threading.Thread.Sleep(1)
Next
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)
mouse_event(&H2&, 0, 0, 0, 0)
mouse_event(&H4&, 0, 0, 0, 0)
Me.BringToFront()
Me.Focus()
End If
End If
End Sub
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.TopMost = True
Me.KeyPreview = True
_mouseStartPositionSet = False
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
CmdPos.BackColor = Color.Green
End Sub
Private Sub PosSel_Tick(sender As Object, e As EventArgs) Handles PosSel.Tick 'Method that waits for the timer to tick, once it has we get the mouse's current position and sets the start location variable
mouseActionStartPosition = Tuple.Create(Cursor.Position.X, Cursor.Position.Y)
lblMousePos.Text = "Mouse Pos: " & Cursor.Position.X & ":" & Cursor.Position.Y
CmdPos.BackColor = Color.Red
_mouseStartPositionSet = True
PosSel.Enabled = False
End Sub
End Class