A little tool I made, changing firemode between auto, slowauto, burst and semi in games and also tracking open window having keybound mousespam.
Code:
// By xetal
using System;
using System.Diagnostics;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Threading;
namespace autoclick
{
class Autoclick
{
[DllImport("user32.dll")]
internal static extern short GetAsyncKeyState(int hotkey);
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr handle, uint msg, int wp, int lp);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetWindowThreadProcessId(IntPtr handle, out int p);
static uint ner = 0x100;
static uint upp = 0x101;
private static bool[] loop = new bool[5];
private static bool spam = true;
private static int msec = 35;
static void Main(string[] a)
{
Console.Title = "Firetoggle by xetal";
int[] param;
if (a.Length >= 2)
{
string s = a[0].TrimStart('-');
param = new int[2];
try { param[0] = Convert.ToInt32(s); }
catch { param = input(); }
if (a[1] == "-toggle")
spam = false;
else if (a[1] == "-multi")
multi(param[0], 50, 80);
else if (a[1] != "-spam")
param = input();
if (a.Length == 3)
try { msec = Convert.ToInt32(a[2].TrimStart('-')); }
catch { };
}
else
{
param = input();
multi(param[0], 35, 0);
}
int key = param[0];
threader();
if (!spam)
toggle(key);
Console.WriteLine("Mode: Spam");
while (true)
{
bool hit = false;
if (GetAsyncKeyState(key) < 0)
{
hit = true;
if (!loop[0])
{
loop[0] = true;
Console.WriteLine("Starting");
}
}
if (!hit && loop[0])
{
loop[0] = false;
Console.WriteLine("Stopping");
}
Thread.Sleep(1);
}
}
static void toggle(int key)
{
Console.WriteLine("Mode: Toggle");
bool down = false;
bool beenup = true;
while (true)
{
bool hit = false;
if (GetAsyncKeyState(key) < 0)
{
if (beenup)
{
if (!down)
down = true;
else
{
down = false;
Console.Write("\a");
}
Console.WriteLine("Enabled: {0}", down);
beenup = false;
}
}
else
beenup = true;
if ((GetAsyncKeyState(1) < 0) && down)
{
hit = true;
if (!loop[mode])
{
loop[mode] = true;
Console.WriteLine("Starting");
}
}
if (!hit && loop[mode])
{
loop[0] = false;
Console.WriteLine("Stopping");
}
Thread.Sleep(1);
}
}
static void press(Process h)
{
while (true)
{
while (loop[0])
{
while (!change && loop[0])
{
PostMessage(h.MainWindowHandle, upp, 1, 0);
PostMessage(h.MainWindowHandle, ner, 1, 0);
PostMessage(h.MainWindowHandle, upp, 1, 0);
Thread.Sleep(msec);
}
h = pid();
change = false;
}
Thread.Sleep(1);
}
}
static void slowauto(Process h, int call)
{
int local = mode;
while (true)
{
if (local != mode)
{
h = pid();
local = mode;
}
while (loop[1])
{
while (!change && loop[1])
{
if (GetAsyncKeyState(1) < 0)
{
PostMessage(h.MainWindowHandle, upp, call, 0);
PostMessage(h.MainWindowHandle, ner, call, 0);
PostMessage(h.MainWindowHandle, upp, call, 0);
Thread.Sleep(160);
}
Thread.Sleep(1);
}
h = pid();
change = false;
}
Thread.Sleep(100);
}
}
static void auto(Process h, int call)
{
int local = mode;
while (true)
{
if (local != mode)
{
h = pid();
local = mode;
}
while (loop[0])
{
while (!change && loop[0])
{
while (GetAsyncKeyState(1) < 0)
{
PostMessage(h.MainWindowHandle, upp, call, 0);
PostMessage(h.MainWindowHandle, ner, call, 0);
PostMessage(h.MainWindowHandle, upp, call, 0);
Thread.Sleep(35);
}
Thread.Sleep(1);
}
h = pid();
change = false;
}
Thread.Sleep(1);
}
}
static void burst(Process h, int call)
{
int local = mode;
bool beenup = true;
while (true)
{
if (local != mode)
{
h = pid();
local = mode;
}
while ((loop[2]) || (loop[3]))
{
int l = mode;
while (!change && loop[l])
{
if (GetAsyncKeyState(1) < 0)
{
if (beenup)
{
for (int i = 0; i < 3; i++)
{
PostMessage(h.MainWindowHandle, upp, call, 0);
PostMessage(h.MainWindowHandle, ner, call, 0);
PostMessage(h.MainWindowHandle, upp, call, 0);
if (mode == 3)
break;
Thread.Sleep(100);
}
if (mode == 2)
Thread.Sleep(175);
beenup = false;
}
}
else
beenup = true;
Thread.Sleep(1);
}
h = pid();
change = false;
}
Thread.Sleep(100);
}
}
static void window()
{
IntPtr winholder = GetForegroundWindow();
IntPtr hold = winholder;
while (true)
{
while (winholder == hold && !change)
{
winholder = GetForegroundWindow();
Thread.Sleep(100);
}
if (!change)
hold = winholder;
change = true;
Thread.Sleep(10);
}
}
static void threader()
{
Thread t1 = new Thread(() => press(pid()));
Thread t2 = new Thread(window);
t1.Start();
Thread.Sleep(100);
t2.Start();
}
static private bool change = false;
static Process pid()
{
int p;
GetWindowThreadProcessId(GetForegroundWindow(), out p);
Process ret = Process.GetProcessById((int)p);
Console.WriteLine(ret.ProcessName);
return ret;
}
static int[] input()
{
Console.WriteLine("There was a problem parsing the command line. First param must be int 0-255 and second toggle/spam.");
Console.WriteLine("Press the key you want to be assigned for autoclick!");
int[] r = new int[2];
bool stop = false;
while (!stop)
{
for (int i = 0; i < 256; i++)
if ((GetAsyncKeyState(i) < 0) && (i > 3))
{
r[0] = i;
stop = true;
}
Thread.Sleep(1);
}
jump:
Console.WriteLine("\n{0} assigned!\nSelect mode:\n1)Toggle (spam with left mouse while toggeled by key)\n2) Spam while key is down regardless of mouse ", r[0]);
string input = Console.ReadLine();
if (input == "1")
spam = false;
else if (input != "2")
goto jump;
r[1] = Convert.ToInt32(input);
return r;
}
static int mode = 0;
static void multi(int togglekey, int msec, int eventkey)
{
bool stop = false;
if (eventkey == 0)
{
Console.WriteLine("Please press a key that's not used by the game and then assign the left mouse event to it!\n\nPress a key:");
while (!stop)
{
for (int i = 0; i < 256; i++)
if ((GetAsyncKeyState(i) < 0) && (i > 3))
{
eventkey = i;
stop = true;
}
Thread.Sleep(1);
}
}
Thread t1 = new Thread(() => slowauto(pid(), eventkey));
Thread t2 = new Thread(() => auto(pid(), eventkey));
Thread t3 = new Thread(() => burst(pid(), eventkey));
Thread t4 = new Thread(window);
t1.Start(); t2.Start(); t3.Start(); t4.Start();
string[] modename = { "Auto", "Slow-auto", "Burst", "Semi", "Off" };
bool been = true;
while (true)
{
if (GetAsyncKeyState(togglekey) < 0)
{
if (been)
{
mode = keyn(mode);
for (int i = 0; i < 4; i++)
if (i != mode)
loop[i] = false;
else
loop[i] = true;
been = false;
Console.WriteLine("Mode: {0}", modename[mode]);
}
}
else
been = true;
Thread.Sleep(1);
}
}
static int keyn(int k)
{
if (k == 4)
k = 0;
else
k++;
if (k == 4)
Console.Write("\a");
return k;
}
}
}