Results 1 to 4 of 4
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10

    [C++] How to make a simple bot

    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.
     #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 SendInput().
    SendInput - Synthesizes keystrokes, mouse motions, and button clicks.
    The SendInput function requires the use of the INPUT object.
    INPUT - Used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
    . So let us declare an INPUT object and have it setup for a mouse click.
     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 mouse to do. In this case, we want to move the mouse. That is why we used MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE.
    MOUSEEVENTF_ABSOLUTE - Contains information about a simulated mouse event.
    Next we filled in the X and Y position of where we want the mouse to land.

    Now we can move on to SendInput.
     SendInput(true, &Input, sizeof(Input)); 

    After this piece of code, you will notice the mouse does move. 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.
     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.
     INPUT Input;
    Input.type = INPUT_KEYBOARD;
    Input.ki.dwFlags = /* Figure it out yourself */
    Input.ki.wVk = Virtual Key Codes;

    Virtual Key Codes Table
    The hint here is that it is very similar to a mouse click but, you use this KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP.
     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.
     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 use the Sleep() function for delays between keystrokes.
    Author: ?(^_^?)(?^_^)?
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  2. #2
    sh1ft
    sh1ft is offline
    New member sh1ft's Avatar
    Join Date
    2011 Dec
    Location
    Asia
    Posts
    17
    Thanks Thanks Given 
    9
    Thanks Thanks Received 
    10
    Thanked in
    4 Posts
    Rep Power
    0
    Even the simple code kinda confuse me lol.
    Btw Dwar..should i start learn from c language or assembly first

  3. #3
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10
    Quote Originally Posted by sh1ft View Post
    should i start learn from c language or assembly first
    It's depended on your aim... if you have free time, if you already know what programming is, you can try ASM. No matter what you choose, just learn and improve your skills
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  4. The Following User Says Thank You to Dwar For This Useful Post:


  5. #4
    kerapu
    kerapu is offline
    Guest
    Join Date
    2014 Oct
    Location
    malaysia
    Posts
    1
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0

    thanks

    can you make some video tutorial

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •