Results 1 to 4 of 4

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Posting Permissions

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