Hello! Welcome to my little guide about how to make a simple Anti-AFK Bot, with background mode!
This isn't some big Memory reading / writing bot, it's a simple application, but it gets the job done. :-)
First, we're going to create a Windows Form Application, then create 2 buttons, a "Start Bot", and a "Stop Bot".
Then double-click on the Start button, and you should find yourself in the code part of the program. Now go to the top of the code document, and you should see some code that looks like this:
Code:
using System;
using System.Data;
and so on, in the end of that, insert this:
Code:
using System.Threading;
using System.Runtime.InteropServices;
Under this, write the following:
Code:
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Keys wParam, Int32 lParam);
Yes, I know that isn't the best way to use SendMessage, but it's much easier if you're only going to use it for this.
and under that, write this:
Code:
private void SendTast(IntPtr hWnd, Keys wParam) {
IntPtr hWnd = FindWindow(null, "World of Warcraft");
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
SendMessage(hWnd, WM_KEYDOWN, wParam, 0);
SendMessage(hWnd, WM_KEYUP, wParam, 0);
}
under that write this:
Code:
private void AfkThread() {
IntPtr hWnd_WoW = FindWindow(null, "World of Warcraft");
System.Random RInterval = new System.Random(0);
int WaitInterval;
for(; ; ) {
SendTast(hWnd_WoW, Keys.A);
WaitInterval = RInterval.Next(17, 77);
Thread.Sleep(WaitInterval*1000);
SendTast(hWnd_WoW, Keys.Space);
WaitInterval = RInterval.Next(17,77);
Thread.Sleep(WaitInterval*1000);
SendTast(hWnd_WoW, Keys.S);
WaitInterval = RInterval.Next(17, 77);
Thread.Sleep(WaitInterval*1000);
}
}
Before the button_press code, write this:
Now go in the button code again, and write the following:
Code:
oAfk = new Thread(AfkThread);
oAfk.Start();
Then, go out to the formdesigner, and double-click the Stop Button, this should bring you to the code part of the button, and then in the button_press, write this:
the code file should now look like this:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
namespace AntiAFK
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Keys wParam, Int32 lParam);
private void SendTast(IntPtr hWnd, Keys wParam)
{
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
SendMessage(hWnd, WM_KEYDOWN, wParam, 0);
SendMessage(hWnd, WM_KEYUP, wParam, 0);
}
private void AfkThread()
{
IntPtr hWnd_WoW = FindWindow(null, "World of Warcraft");
System.Random RInterval = new System.Random(0);
int WaitInterval;
for (; ; )
{
SendTast(hWnd_WoW, Keys.A);
WaitInterval = RInterval.Next(17, 77);
Thread.Sleep(WaitInterval * 1000);
SendTast(hWnd_WoW, Keys.Space);
WaitInterval = RInterval.Next(17, 77);
Thread.Sleep(WaitInterval * 1000);
SendTast(hWnd_WoW, Keys.S);
WaitInterval = RInterval.Next(17, 77);
Thread.Sleep(WaitInterval * 1000);
}
}
Thread oAfk;
private void button1_Click(object sender, EventArgs e)
{
oAfk = new Thread(AfkThread);
oAfk.Start();
}
private void button2_Click(object sender, EventArgs e)
{
oAfk.Abort();
}
}
}
Now execute the program. GL and HF.
Any questions, just leave a reply, or give me a PM.