Well I am making an AFK Bot for a FPS game called Combat arms.
What it is supposed to do is Move Up, Down, Left, and Right by itself while I am AFK.
I want it to press Spacebar to jump too.

I also want it to Press the Left button of the Mouse so it can shoot while I am AFK.

I was told the SendInput() function could do this for me. So I looked at Msdn and googled it a bit, I got some source codes but it was a bit confusing. I had no idea how it worked. I mean how could I use a code if I don't know how to really work the function? It seems that it presses Key_Up for me in notepad, I tried and noting.

I was hoping for you guys to tell me how I could go about making the bot with the correct function and explain how it works.
Maybe you could even give me a example source code that works?

I need an example for both Mouse click and Key Press.
Once I have a nice example I will be set.
I learn really fast.


[Extra notes]: Yes I know basic c++, I am a game programmer, and I pretty much know enough to make programs on my own. Once You show me a good source code and tell me how it works i'll know what to do from there.

Look up ray casting for the mouse click and shoot. Basically what
you need to do is have a line defined from the mouse click point to
the player position vector. Then you have a line from the player
to the spot where you clicked with your mouse. Now you some
maybe particles system that shoots out some flares or whatever
you decide to shoot, following the line or a parabolic trajectory
the has its endpoint at the end of the line.

To move left, right, up or down, you need some sort of intermediate
that transfers data from your keys to the graphics windows.
glut has its own ways, and so does win32. Have some sort of
intermediate that tells your when the left,right,up or down keys
were pressed. When when one button is pressed, move the object
accordingly.

For jumping what I do is to have 2 functions. One function that
handles going up, and other going down. It makes it easier for
me later on to modify the height/speed of jumping up or down.

You could do it in 1 function. All you need is impulse, initial velocity,
acceleration, gravity, and other Newtonian equations that deals
with motion. The gravity should be the deciding factor on how high
an object goes up. It should slowly decrease the object
acceleration thus making it go up to a certain height and after
reaching its peak, slowly decrease in height.

Maybe mouse_event and keybd_event is what you're looking for, i'll provide a couple of examples.

  • Simple mouse click
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  • Press space bar
    keybd_event( VK_SPACE, 0x45, KEYEVENTF_EXTENDEDKEY, 0 );
    keybd_event( VK_SPACE, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.