[C++] Tutorial: How to make a bot
by ヘ(^_^ヘ)(ノ^_^)ノ
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.
The first function we can use to simulate keystrokes or mouse functions is SendInput(). The SendInput function requires the use of the INPUT object. So let us declare an INPUT object and have it setup for a mouse click.Código:#include//This is what we need for the SendInput functions int main() { return 0; }
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 MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE. Next we filled in the X and Y position of where we want the mouse to land.Código: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));
Now we can move on to SendInput.
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.Código:SendInput(true, &Input, sizeof(Input));
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.
Here is a keystroke example with the keyboard input.Código: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));
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.Código:INPUT Input; Input.type = INPUT_KEYBOARD; Input.ki.dwFlags = /* Figure it out yourself */ Input.ki.wVk = Virtual Key Codes;
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.Código:... Input.ki.wvK = 'A'; Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; SendInput(true, &Input, sizeof(Input)); Input.ki.dwFlags = KEYEVENTF_KEYUP; SendInput(true, &Input, sizeof(Input));
Código: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. }
0 comentarios:
Publicar un comentario