Boost Your Website Traffic
Try the new KongHack Ad Manager
Increase your traffic today!
[Information] Auto Clicker for the tech savy
Auto Clicker in C++
Auto Clicker for the tech savy Posted on: 09/04/2016 10:25am
Quote Post

Compile this code in C++

Clicker - Hold
Clicker - Toggle

Edit the key you want to use for the program on line 16 of each code, values are here. The mouse buttons are gonna require trial and error as shown in the coment of the line "VK_RBUTTONDOWN = Middle click".

Control click frequency at line 36 for hold and 33 for toggle.

Important requirements:
In order to compile this code you'll need to install the pthreads library through MinGW.
In order to run the program outside of the compiler you'll have to add the "MinGW\bin" folder to PATH.

This is primarily for the tech savy, but with a bit of googling about just about anyone can get the code running and save real money on mouse hardware.

Edit: I've cleaned the code a bit further thanks to ZuckeR. I've also added the first version of the code that was made to work while you hold the key, it might suit some people so there it goes.

RE: Auto Clicker for the tech savy Posted on: 09/04/2016 7:10pm
Quote Post


It does indeed work but seems kinda odd in a few ways.

  1. Program compiles fine without winable.h and stdio.h, i guess you left them here after trying something.
  2. You left in target, pt, wrect in the main function but they never get used. -Wall does not like that so i had to remove those.
  3. Those while loops that trap the input are weird on the first look but work better than i would have expected. I tried to find another way but failed although i think there are better ways to do a toggable button.
  4. Why do you need pthreads i don't see for what it is needed. Maybe with mingw it is always needed and i just never noticed :P

Those are just tiny things and it does work for such a simple program. It comes out pretty small as well with just 17.4kb (64-bit) and 12.0kb (32-bit). A nice base to build upon to if you like to fiddle around a bit. Anyways, here is the cleaned up version i did compile from:
 

http://pastebin.com/cSCv3jfW

g++ -o clicker.exe main.cpp -Wall -s -O3



khwar.com
RE: Auto Clicker for the tech savy Posted on: 09/05/2016 12:57pm
Quote Post

Thanks for the feedback, I never though about what the program needed and didn't need, I dug it out after a PC format and 3 months since last touching it.
I'm gonna work on the optimization a bit and see what I can come up with, codeblocks isn't as good as eclipse for pointing out things like unused variables and useless code. Turns out the things you removed because of your -Wall thing weren't needed after all.

The toggle function came as a result of my fingers hurting from keeping the key pressed down and Do It Again's numerous problems when it comes to things like leaving it running for a long time.

Pthreads is for the sleep() function. Yes, you can compile it without that library, but you'll be unable to configure the frequency of clicks and the program is gonna hog a full processor core while idle. It's the reason there's a sleep(100) in one of the while loops. You can get the program to go as fast as your computer would allow by removing the sleep from the while loop, the problem is finding a game that will accept that fast of an input.

I just noticed the first comment block in the code, it's a source from where I took the base of the code and then mangled it till it bent to what I needed, it was meant to keep clicking while I kept the middle button down, one of my atempts of getting an auto clicker to work on Dungeon Fighter Online, too bad it fell flat on its face.

P.S. I'm still an amateur coder when it comes to programming, things like using programming IDE's and sticking to Windows 7.

RE: Auto Clicker for the tech savy Posted on: 09/05/2016 3:00pm
Quote Post

Yeah leaving your code lying around doing nothing can be good. I just "love" to come back to old code, not understanding and having to rewrite it :P

I do not use Codeblocks or Eclipse but simply Notepad++. I used Codeblocks in the beginning but as i wanted to use makefiles for compiling it kinda sucked at that. I generally don't like those IDEs so much as you have to create a new project for a simple hello world program. Within my makefiles i always try to use -Wall for showing almost all errors that can and should be fixed even if the program would work with those mistakes. Notepad++ does not show me anything at all.

Not sure about the pthreads as it does not mention to have the sleep function in there. It is in unistd.h though. In the case of this little program it is the wrong function anyways. You are using the WinAPI Sleep() and not the POSIX sleep() but they do pretty much the same stuff. As this is nonportable anyways the program would not benefit from using the POSIX version.

I am an amateur as well doing programming just for fun.




khwar.com
More Macros Posted on: 09/09/2016 2:58pm
Quote Post

Bonus stuff I've just finished cleaning up:

Press E
Press E - Toggle

These function in a very similar manner to the clicker, but will instead generate keyboard events.
To change which key starts the macro, alter where it says "WM_RBUTTONDOWN".
To change which key the macro repeatedly sends to the computer alter the 0x45 on lines 19 for the first code and 20 for the second.

They also require MinGW.

@ZuckeR: I remember now why it had the extra libraries, in order to make head and tails of what the heck a code is doing I fill it with printf's in several places it helps detecting where a program gets stuck.

RE: Auto Clicker for the tech savy Posted on: 09/11/2016 9:33am
Quote Post

Really cool, those should be combined into one tool that can do both. I tried that with the clicker in a way that it supports toggled and untoggled mode. Here is the code: http://pastebin.com/6cyPgLRf

You can then run it like so: clicker.exe -k a -s 1 -t

I use the normal main instead of WinMain as it is weird to work with command line options in the windows version. Fetching the arguments is done with getopt which is really easy to use. -k sets the key, -s the sleeping time and if -t is set the program runs in toggle mode. This isn't quite optimal but works for now. -k just works with letters and numbers for now, maybe it should accept keycodes.

You are right with using printf for simple error hunting, i also do that. I have literally no experience with debuggers so i have to rely on that and the compiler. Now its in there anyways as i am printing the setup info at the very beginning.

And by the way i am using C++ here while this is still technically pure C here if you change the headers.




khwar.com
RE: Auto Clicker for the tech savy Posted on: 09/14/2016 1:40pm
Quote Post

Now you've gone and done it, can't make head nor tails of the code just by looking at it.
I rarely run stuff with command lines, it's why I kept it as 2 separate programs.
This new code you've concocted seems to be more than twice the size of the previous ones and also has 3 times the complexity.
I'm gonna look at it though, if the goal was to make it into something where you have both options into a single program then I'm sure it can be trimmed down.

RE: Auto Clicker for the tech savy Posted on: 09/14/2016 2:16pm
Quote Post

OK, this way of trapping the whole loop for key checks annoyed me more than i would have thought. The problem with those traps is that you could not do that for more than one key and it stops the rest of the program. While trying to create that simple clicker with the main Windows methods i encountered that problem again.

Usually when you create a WinAPI program it runs a window procedure. LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) Now looking if msg is WM_KEYUP you can use that to do a toggle. But that just works if the window is active and it does not register input on other programs.

So i was back at trying to use this while trapping again but it would have halted the program. I fiddled around for a while and got to a way that works good enough. You can simply check for a keystate and compare it to its last saved state.

bool down_prev = false;
bool down_now = false;

down_now = KeyIsPressed( key );
if (!down_prev && !down_now) { // not pressed}
if (!down_prev && down_now) { // keydown This is what we need }
if (down_prev && down_now) { // holding }
if (down_prev && !down_now) { // keyup }
down_prev = down_now;

This works for one button but with a buffer (or two) would do work with the whole keyboard and mouse. Now we do not need those traps and can do everything in the main loop. It allows me to use the timer functions of the WinApi and create a GUI version of this.

http://pastebin.com/DXUkJXXD




khwar.com
RE: Auto Clicker for the tech savy Posted on: 10/26/2016 1:03am
Quote Post

Yay! Thank you, it actually helped me in a different way than it was intended to, but, hey, that's a good thing :D