How to make an inactive window work and respond to buttons (C# .NET windows forms)
-
I have such a clicker, I want to be able to continue, for example, after opening another application, or vice versa. Please help All code here:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace Klikacz____TzPw
{public partial class Form1 : Form { \[DllImport(dllName: "User32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)\] public static extern void mouse\_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); private const int LEFTUP = 0x0004; private const int LEFTDOWN = 0x0002; public Form1() { InitializeComponent(); this.ActiveControl = button1; button1.Focus(); } private void Click\_clock\_Tick(object sender, EventArgs e) { Random rnd = new Random(); int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.2)); int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.4)); try { Click\_clock.Interval = rnd.Next(mincps, maxcps); } catch { //Ignored.. } bool mousdown = MouseButtons == MouseButtons.Left; if (mousdown) { mouse\_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0); Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6)); mouse\_event(dwFlags: LEFTDOWN, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0); } } private void button1\_Click(object sender, EventArgs e) { if (button1.Text.Contains("Uruchom")) { Click\_clock.Start(); button1.Text = "Wstrzymaj"; } else { Click\_clock.Stop(); button1.Text = "Uruchom"; } } private void trackBar1\_Scroll(object sender, EventArgs e) { CPSValue.Text = "CPS = " + trackBar1.Value.ToString(); } }
}
-
I have such a clicker, I want to be able to continue, for example, after opening another application, or vice versa. Please help All code here:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace Klikacz____TzPw
{public partial class Form1 : Form { \[DllImport(dllName: "User32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)\] public static extern void mouse\_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); private const int LEFTUP = 0x0004; private const int LEFTDOWN = 0x0002; public Form1() { InitializeComponent(); this.ActiveControl = button1; button1.Focus(); } private void Click\_clock\_Tick(object sender, EventArgs e) { Random rnd = new Random(); int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.2)); int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + 0 \* 0.4)); try { Click\_clock.Interval = rnd.Next(mincps, maxcps); } catch { //Ignored.. } bool mousdown = MouseButtons == MouseButtons.Left; if (mousdown) { mouse\_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0); Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6)); mouse\_event(dwFlags: LEFTDOWN, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0); } } private void button1\_Click(object sender, EventArgs e) { if (button1.Text.Contains("Uruchom")) { Click\_clock.Start(); button1.Text = "Wstrzymaj"; } else { Click\_clock.Stop(); button1.Text = "Uruchom"; } } private void trackBar1\_Scroll(object sender, EventArgs e) { CPSValue.Text = "CPS = " + trackBar1.Value.ToString(); } }
}
- you can keep things in your app running, whether or not your app is the current active application, by using a Timer, or having a some form of 'while loop. advice : don't use a 'while loop. 2) when your app is not active ... it can still get messages by using a GlobalKeyBoardHook it defines, and registers, that intercepts some keyboard combination of keys. warning: you override some other app's keyboard hooks, and you are in trouble. I believe what you probably need to use is the SystemTray app model, and CP has several articles that will show you how to use that: [^] However, if what you want is some kind of stealth monitoring app: you won't get help with that here.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch