diff --git a/AutoClicker.exe b/AutoClicker.exe deleted file mode 100644 index 0c58726..0000000 Binary files a/AutoClicker.exe and /dev/null differ diff --git a/AutoClicker/ButtonInputs.cs b/AutoClicker/ButtonInputs.cs index 91acd37..6bee2b9 100644 --- a/AutoClicker/ButtonInputs.cs +++ b/AutoClicker/ButtonInputs.cs @@ -5,8 +5,8 @@ namespace AutoClicker { public partial class ButtonInputs : UserControl { - private readonly uint _buttonDownCode; - private readonly uint _buttonUpCode; + private readonly uint buttonDownCode; + private readonly uint buttonUpCode; public bool Needed => cbButtonEnable.Checked; @@ -14,8 +14,8 @@ public ButtonInputs(string buttonName, uint buttonDownCode, uint buttonUpCode) { InitializeComponent(); - this._buttonDownCode = buttonDownCode; - this._buttonUpCode = buttonUpCode; + this.buttonDownCode = buttonDownCode; + this.buttonUpCode = buttonUpCode; cbButtonEnable.Text = buttonName; numDelay.Maximum = int.MaxValue; numDelay.Value = 200; @@ -23,10 +23,10 @@ public ButtonInputs(string buttonName, uint buttonDownCode, uint buttonUpCode) internal Clicker StartClicking(IntPtr minecraftHandle) { - var delay = cbHold.Checked ? 0 : (int)numDelay.Value; - var clicker = new Clicker(this._buttonDownCode, this._buttonUpCode, minecraftHandle); + var delay = (int)numDelay.Value; + var clicker = new Clicker(buttonDownCode, buttonUpCode, minecraftHandle); - clicker.Start(delay); + clicker.Start(delay, cbHold.Checked); return clicker; } diff --git a/AutoClicker/Clicker.cs b/AutoClicker/Clicker.cs index 7ce0ba4..4f39a21 100644 --- a/AutoClicker/Clicker.cs +++ b/AutoClicker/Clicker.cs @@ -25,17 +25,28 @@ public Clicker(uint buttonDownCode, uint buttonUpCode, IntPtr minecraftHandle) private void Timer_Tick(object sender, EventArgs e) { - Click(); + // keep sending hold every tick as well in case they do something to interrupt the input + if(hold) + { + Hold(); + } else + { + Click(); + } } - public void Start(int delay) + public void Start(int delay, bool hold) { + this.hold = hold; Stop(); - hold = (delay == 0); - if (hold) - //Select the minecraft handle with Alt+Tab to not stop holding (when using the program) - Win32Api.PostMessage(minecraftHandle, buttonDownCode, (IntPtr)0x0001, IntPtr.Zero); + if (hold) + { + Hold(); + timer.Interval = delay; + timer.Start(); + + } else { Click(); @@ -52,6 +63,11 @@ public void Stop() Click(); } + private void Hold() + { + Win32Api.PostMessage(minecraftHandle, buttonDownCode, IntPtr.Zero, IntPtr.Zero); + } + private void Click() { Win32Api.PostMessage(minecraftHandle, buttonDownCode, IntPtr.Zero, IntPtr.Zero); diff --git a/AutoClicker/Main.cs b/AutoClicker/Main.cs index ab47af2..d9d02be 100644 --- a/AutoClicker/Main.cs +++ b/AutoClicker/Main.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; namespace AutoClicker @@ -22,7 +23,7 @@ public Main() InitializeComponent(); } - private void Btn_action_Click(object sender, EventArgs e) + private async void Btn_action_Click(object sender, EventArgs e) { try { @@ -68,29 +69,15 @@ private void Btn_action_Click(object sender, EventArgs e) lblStartTime.Text = DateTime.Now.ToString("MMMM dd HH:mm tt"); lblStarted.Visible = true; lblStartTime.Visible = true; - + foreach (var mcProcess in mcProcesses) { - SetControlPropertyThreadSafe(btn_start, "Enabled", false); - SetControlPropertyThreadSafe(btn_stop, "Enabled", true); - var minecraftHandle = mcProcess.MainWindowHandle; FocusToggle(minecraftHandle); - SetControlPropertyThreadSafe(btn_start, "Text", @"Starting in: "); - Thread.Sleep(500); - - for (var i = 5; i > 0; i--) - { - SetControlPropertyThreadSafe(btn_start, "Text", i.ToString()); - Thread.Sleep(500); - } + await Task.Run(() => CountDown(mainHandle)); - FocusToggle(mainHandle); - SetControlPropertyThreadSafe(btn_start, "Text", @"Running..."); - Thread.Sleep(500); - - //Right click needs to be ahead of left click for concrete mining + // Right click needs to be ahead of left click for concrete mining if (biRightMouse.Needed) { var clicker = biRightMouse.StartClicking(minecraftHandle); @@ -117,6 +104,22 @@ private void Btn_action_Click(object sender, EventArgs e) } } + private void CountDown(IntPtr mainHandle) + { + SetControlPropertyThreadSafe(btn_start, "Text", @"Starting in: "); + Thread.Sleep(750); + + for (var i = 5; i > 0; i--) + { + SetControlPropertyThreadSafe(btn_start, "Text", i.ToString()); + Thread.Sleep(750); + } + + FocusToggle(mainHandle); + SetControlPropertyThreadSafe(btn_start, "Text", @"Running..."); + Thread.Sleep(750); + } + private void AddToInstanceClickers(Process mcProcess, Clicker clicker) { if (instanceClickers.ContainsKey(mcProcess)) diff --git a/AutoClicker/MultipleInstances.cs b/AutoClicker/MultipleInstances.cs index 99266d9..874c32a 100644 --- a/AutoClicker/MultipleInstances.cs +++ b/AutoClicker/MultipleInstances.cs @@ -16,10 +16,10 @@ public MultipleInstances(IEnumerable foundProcesses) { InitializeComponent(); - this.SelectedInstances = new List(); + SelectedInstances = new List(); const int x = 25; var y = 20; - var buttonX = this.grpInstances.Location.X + this.grpInstances.Width - 100; + var buttonX = grpInstances.Location.X + grpInstances.Width - 100; var processCount = 0; foreach (var process in foundProcesses) @@ -40,8 +40,8 @@ public MultipleInstances(IEnumerable foundProcesses) button.Click += (sender, e) => { Win32Api.SetForegroundWindow(process.MainWindowHandle); }; - this.grpInstances.Controls.Add(checkbox); - this.grpInstances.Controls.Add(button); + grpInstances.Controls.Add(checkbox); + grpInstances.Controls.Add(button); y += 25; processCount++; @@ -51,7 +51,7 @@ public MultipleInstances(IEnumerable foundProcesses) private void Btn_ok_Click(object sender, EventArgs e) { - var selectedInstances = this.grpInstances.AllControls().Where(b => b.Checked).ToList(); + var selectedInstances = grpInstances.AllControls().Where(b => b.Checked).ToList(); if (!selectedInstances.Any()) { @@ -60,20 +60,20 @@ private void Btn_ok_Click(object sender, EventArgs e) } foreach (var instance in selectedInstances) - this.SelectedInstances.Add(int.Parse(instance.Value)); + SelectedInstances.Add(int.Parse(instance.Value)); - this.DialogResult = DialogResult.OK; - this.Close(); + DialogResult = DialogResult.OK; + Close(); } private void AdjustForm(int processCount) { if (processCount > 4) { - this.grpInstances.Height += 25; - this.Height += 25; - this.btn_cancel.Location = new Point(this.btn_cancel.Location.X, this.btn_cancel.Location.Y + 25); - this.btn_ok.Location = new Point(this.btn_ok.Location.X, this.btn_ok.Location.Y + 25); + grpInstances.Height += 25; + Height += 25; + btn_cancel.Location = new Point(btn_cancel.Location.X, btn_cancel.Location.Y + 25); + btn_ok.Location = new Point(btn_ok.Location.X, btn_ok.Location.Y + 25); } } }