Simple autoclicker

This is a discussion on Simple autoclicker within the Windows Programming forums, part of the Platform Specific Boards category; My friend asked me to make him a simple auto clicker(always the same coordinate) for some game he plays. This ...

  1. #1
    The Registered User Aparavoid's Avatar
    Join Date
    May 2009
    Posts
    74

    Simple autoclicker

    My friend asked me to make him a simple auto clicker(always the same coordinate) for some game he plays. This is what I have so far:

    Code:
    #include <windows.h>
    
    int main(void)
    {
    	HWND window = FindWindow(NULL, "RSCEmulation V6");
    	for(;;)
    	{
    		SendMessage(window, WM_LBUTTONDOWN, , MK_LBUTTON);
    	}
    	return 0;
    }
    Is the code, besides the missing argument, I already have ok? How do you turn the coordinate (256, 245) into an integer with the low word as X and the high word as Y?

    Thanks

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Aparavoid View Post
    How do you turn the coordinate (256, 245) into an integer with the low word as X and the high word as Y?
    Code:
    DWORD val = ( y << 16 ) | x;
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    The Registered User Aparavoid's Avatar
    Join Date
    May 2009
    Posts
    74
    Quote Originally Posted by brewbuck View Post
    Code:
    DWORD val = ( y << 16 ) | x;
    Thank you brewbuck that works well. The only problem now is the location of the mouse event follows the actual mouse instead of the third argument which is now ( 245 << 16 ) | 256.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Aparavoid View Post
    Thank you brewbuck that works well. The only problem now is the location of the mouse event follows the actual mouse instead of the third argument which is now ( 245 << 16 ) | 256.
    How are you testing it? In the game itself?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    The Registered User Aparavoid's Avatar
    Join Date
    May 2009
    Posts
    74
    I found the problem. The 3rd and 4th arguments were switched. Thanks for the help.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Aparavoid View Post
    I found the problem. The 3rd and 4th arguments were switched. Thanks for the help.
    How disappointing I was going to speculate that the game had some anti-hacking built into it to prevent this kind of auto clicking. (It's not hard, you just ignore the coordinates in the event and query the mouse position directly, which forces the autoclicker to actually move the mouse pointer, which would probably disrupt game play)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You can also use the macros

    MAKEWPARAM()
    MAKELPARAM()

    and the reverse

    HIWORD()
    LOWORD()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by brewbuck View Post
    How disappointing I was going to speculate that the game had some anti-hacking built into it to prevent this kind of auto clicking. (It's not hard, you just ignore the coordinates in the event and query the mouse position directly, which forces the autoclicker to actually move the mouse pointer, which would probably disrupt game play)
    Read the mouse coordinates before you move it, move it, click then move it back. Or just directly inject the WM_ messages into the application queue. Checkign current mouse coords wouldn't work as its possible the mouse has moved since the click was made.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Depending on app structure, InSendMessage() can be used to filter external msgs.

    Quote Originally Posted by abachler View Post
    Or just directly inject the WM_ messages into the application queue.
    SendMessage() is nonqueued, so faster and more reliable.

    Using PostMessage() would require more checking for a game (as it's msg queue may be full most of the time, causing PostMessage() to fail),
    Last edited by novacain; 12-24-2009 at 09:09 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 06:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21