[C++] Tutorial: How to make a bot

Discussion in 'Tutorials & Source Codes' started by ヘ(^_^ヘ)(ノ^_^)ノ, Jun 21, 2010.

  1. ヘ(^_^ヘ)(ノ^_^)ノ

    ヘ(^_^ヘ)(ノ^_^)ノ Fanatic Hacker

    Post Count:
    217
    Likes Received:
    3
    Stats
    I will assume you know how to create an empty C++ project and add a source file. In this tutorial I will explain to you how to program a bot. I will not post enough of the source code for you to make a copy pasta bot.

    First, you will need to include the windows.h header file.
    Code:
    #include <windows.h> //This is what we need for the SendInput functions
    int main()
    { 
         return 0;
    }
    
    The first function we can use to simulate keystrokes or mouse functions is . The SendInput function requires the use of the object. So let us declare an INPUT object and have it setup for a mouse click.
    Code:
    INPUT Input;
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
    Input.mi.dx = X * (65535.0f / (GetSystemMetrics(SM_CXSCREEN) -1));
    Input.mi.dy = Y * (65535.0f / (GetSystemMetrics(SM_CYSCREEN) -1));
    
    If you just put this code in and compile + debug it, nothing will happen because we did not pass this through SendInput yet. Before I explain how to use SendInput, I will explain what this code above means. Since we set the input type to INPUT_MOUSE, we fill in Input.mi.dwFlags with what we want the mosue to do. In this case, we want to move the mouse. That is why we used . Next we filled in the X and Y position of where we want the mouse to land.

    Now we can move on to SendInput.
    Code:
    SendInput(true, &Input, sizeof(Input));
    
    After this piece of code, you will notice the mouse does move. If you are not a complete moron, you should know where this goes.

    Try to make the mouse click now. You should used MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP. You also need to call SendInput twice. Only look if you cannot get it, dumbass.
    Code:
    INPUT Input;
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;     //Clicks the mouse down.
    SendInput(true, &Input, sizeof(Input));
    Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;       //Releases the mouse clock.
    SendInput(true, &Input, sizeof(Input));
    

    Here is a keystroke example with the keyboard input.
    Code:
    INPUT Input;
    Input.type = INPUT_KEYBOARD;
    Input.ki.dwFlags = /* Figure it out yourself */
    Input.ki.wVk = 
     
    ;
    
    The hint here is that it is very similar to a mouse click but, you use this KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP. Only look if you cannot figure it out. Dumbass.
    Code:
    ...
    Input.ki.wvK = 'A';
    Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
    SendInput(true, &Input, sizeof(Input));
    Input.ki.dwFlags = KEYEVENTF_KEYUP;
    SendInput(true, &Input, sizeof(Input));
    

    Now you need to turn it on and off. The smart way to do this is create a thread and have it watch for the hotkeys and then create another thread to simulate those keystrokes. For this we need the CreateThread function.
    Code:
    int main()
    {
         DWORD dwHandleHotKeys;
         CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)HandleHotKeys, NULL, NULL, &dwHandleHotKeys);
         //On Exit
         ExitThread(dwHandleHotKeys);
    }
     
    void HandleHotKeys()
    {
         //Create a loop to look for hotkeys.
    }
    
    Before I close off this tutorial, I should tell you that this is probably blocked by MANY anti-hacking applications. And for those who dosen't know yet, use the Sleep() function for delays between keystrokes. For any further questions please contact my person assistant. .

    Tired of seeing C++ tutorials that never got past making your own functions like add() or sub(). Not one C++ tutorial in this section have I seen that got to using windows APIs or did not spoonfeed the reader.
     
    donghyun, Viriatus and Vence like this.

    Mr. Ad Advertisement

     
  2. Michalol

    Michalol Informed Hacker

    Post Count:
    51
    Likes Received:
    0
    Stats
    Hey first thanks for the tutorial,and now i just started with C++ , so please tell me what files in need to make and where to include everything =]
    thanks
     
  3. Hippie

    Hippie Lurker

    Post Count:
    1
    Likes Received:
    0
    Stats
    I am also beginning C++ i use to be a fan of visual basic's but i've found that when you code in VB your not really considered a coder, and that you can do much more in c++ so i've just began doing this and your tutorial is very easy to follow, nice tutorial. :D
     
  4. math-mania

    math-mania Lurker

    Post Count:
    1
    Likes Received:
    0
    Stats
    Very nice tutorial, it is very easy to understand for a people who start to learn c++ like me
     
  5. Sora

    Sora Australia Prominent Hacker

    Post Count:
    594
    Likes Received:
    0
    Stats
    nice tut. ;p
    what c/c++ program do you use?:colbert:
     
  6. kmn101

    kmn101 The New Guy

    Post Count:
    15
    Likes Received:
    0
    Stats
    should the end file be names .bat? or .exe?
     
  7. Connected

    Connected Guest

    Stats
    If you make it for MapleStory, then you should make a DLL project.

     
  8. cancar123

    cancar123 The New Guy

    Post Count:
    13
    Likes Received:
    0
    Stats
    Which program did you use?
     
  9. darkfire

    darkfire The New Guy

    Post Count:
    21
    Likes Received:
    1
    Stats
    Great tutorial but, people are learning nothing from this, with the exception of Copying and Pasting.

    Try putting it all in notepad and taking a picture.
    Make people type and actually understand what your teaching..


    But yeah nice tutorial :)
     
    BoozeAddict likes this.
  10. Famous

    Famous United States Game Killer

    Post Count:
    3,308
    Likes Received:
    0
    Stats
    yeah you make a great point. the best way to learn programming is by doing it yourself.
     
  11. gothixxx12

    gothixxx12 Lurker

    Post Count:
    7
    Likes Received:
    0
    Stats
    how do you make it undetected ??
     
  12. gothixxx12

    gothixxx12 Lurker

    Post Count:
    7
    Likes Received:
    0
    Stats
    famous ?? thats a good idea, why dont you make a step by step guide for us ?? hell anything is good , as long as it can be understood by an idiot. xD

    else if u cant then maybe someone can take famouses great advice ? anyone ?? plz ???

    ---------- Post added at 12:54 AM ---------- Previous post was at 12:53 AM ----------

    oh btw i gave ur lil guys some candy xD
     
  13. Enzo

    Enzo Veteran Hacker

    Post Count:
    186
    Likes Received:
    0
    Stats
    thanks , il try making a bot today if i have time
     
  14. His

    His The New Guy

    Post Count:
    45
    Likes Received:
    0
    Stats
    Thanks for the tutorial.
     
  15. Bountymage

    Bountymage The New Guy

    Post Count:
    42
    Likes Received:
    0
    Stats
    Great tutorial. Helps out a lot.
     
  16. Draken

    Draken United States No creative title here...

    Post Count:
    11,594
    Likes Received:
    3
    Stats
    As said earlier, you made it too copy pasteable lol, maybe you should make a real tut.
     
  17. gothixxx12

    gothixxx12 Lurker

    Post Count:
    7
    Likes Received:
    0
    Stats
    hello i have created a bot for the game tales of pirates. the games now important though. what is is how to get the bot so its not blocked
    this is the source code for my bot it is tested and works as is. how do i get passed the antihack as the sendkeys function is detected. i have been lookiong into api but im not sure how it works.
    it has something to do with a .dll method of direct input. can someone help me ???






    using System;
    using System.Runtime.InteropServices;
    using System.Drawing;
    using System.Windows.Forms;

    namespace SimulateKeyPress
    {
    class Form1 : Form
    {
    private Button button1 = new Button();

    [STAThread]
    public static void Main()
    {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
    }

    public Form1()
    {
    button1.Location = new Point(10, 10);
    button1.TabIndex = 0;
    button1.Text = "Click to automate Calculator";
    button1.AutoSize = true;
    button1.Click += new EventHandler(button1_Click);

    this.DoubleClick += new EventHandler(Form1_DoubleClick);
    this.Controls.Add(button1);
    }

    // Get a handle to an application window.
    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName,
    string lpWindowName);

    // Activate an application window.
    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);

    // Send a series of key presses to the Calculator application.
    private void button1_Click(object sender, EventArgs e)
    {
    // Get a handle to the Calculator application. The window class
    // and window name were obtained using the Spy++ tool.
    IntPtr calculatorHandle = FindWindow("KOP", "Tales of Pirates - The Frozen Relics");

    // Verify that Calculator is a running process.
    if (calculatorHandle == IntPtr.Zero)
    {
    MessageBox.Show("Calculator is not running.");
    return;
    }

    // Make Calculator the foreground application and send it
    // a set of calculations.
    SetForegroundWindow(calculatorHandle);
    SendKeys.SendWait("111");
    SendKeys.SendWait("*");
    SendKeys.SendWait("11");
    SendKeys.SendWait("=");
    }

    // Send a key to the button when the user double-clicks anywhere
    // on the form.
    private void Form1_DoubleClick(object sender, EventArgs e)
    {
    // Send the enter key to the button, which raises the click
    // event for the button. This works because the tab stop of
    // the button is 0.
    SendKeys.Send("{ENTER}");
    }
    }
    }
     
  18. dizzz

    dizzz The New Guy

    Post Count:
    21
    Likes Received:
    0
    Stats
    Nice tutorial.
     
  19. Hero3128

    Hero3128 Japan Elite Hacker

    Post Count:
    1,220
    Likes Received:
    1
    Stats
    nice tutorial bro but you do it so complicated...
    there is a much ezier way
     
  20. onesiteresource

    onesiteresource Lurker

    Post Count:
    1
    Likes Received:
    0
    Stats
    WHOOSH! Straight over my head... I miss HTML :(
     

Share This Page

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies.
    Dismiss Notice
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies.
    Dismiss Notice