Sending Mouse clicks to a window?

Hey I dug out an old game I used to play and just started playing again for fun , but their are some immensely tedious/repetitive tasks I would like to automate (as practice for c++).

I want to click on an NPC and then click on a button that appears above his head and the program wait for me to press ESC key, then loop again and that's about it! So first of all I need to get the co-ordinates of the mouse within the window of the Diablo II (the game) , now I have the co-ordinates of the mouse on the game screen, so far so good!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <Windows.h>

int main()
{
	//Set the D2 Hwnd
	HWND D2Win;
	D2Win = FindWindow (0, "Diablo II");

	if (D2Win == 0){
		std::cout << "Cant find window!";
	}
	else {
		std::cout << "Found him!";
	}

	//Get mouse co-ords of screen
	POINT p;
	GetCursorPos(&p);
	
	//Co-ords in D2
	if (ScreenToClient(D2Win, &p)){
			std::cout << "Mouse pos of D2 window is: " << p.x << "/" << p.y << std::endl;
		}

	std::cin.get();
}


Next I go to the NPC manually (you move in the game by left clicking) I want to now put the mouse over the NPC and log the co-ordinate's as a variable (not sure how I can do this) I then click on him manually and a bubble appears above his head with a button saying "gamble" so I just want to put the mouse over gamble, save those co-ordinates as another variable.

Now all I want to do is send a left mouse click to the first co-ordinate, sleep like 150ms , then send the next left mouse click to the second co-ordinate, wait for an input of ESC key from me , then loop again. I know this is fairly simple I am just not sure how I actually log the co-ordinates from a click to variables, and then send the click to that co-ordinate :P
Up , sorry if I rambled on.

Cliffs: Need to take the co-ords of a mouse click store it in a variable , repeat again and then send those clicks in a loop everytime after I click ESC key.
Topic archived. No new replies allowed.