Mouse clicking c++

Is there a way to right a command that will make the mouse double click or click on a certain spot on the screen? I can make the mouse move to any position that I want but not click.

For example I wanna make a program that will open a game and click in a spot for me.

Also is there a way to make the cursor click and drag?

Thanks!

-Irhcsa
I am confused. You have found a way to move the mouse cursor to a certain part of the screen, and now you want it to be pressed without the user actually pressing it?

It might be better just to have the program do what the mouse click would do. The point of a mouse is for user input. Forgive me if I am completely misunderstanding you though...
Hey ryan, the main point of this is so I can make programs do things for me.

Like in games: I run the program, it opens my game it logs in for me it auto clicks the game settings I want, so I can simply press 1 button and go afk while it does the rest for me.

Best way I can explain it really.

I just need the command that tells the cursor to click and hold and then the command to release.

Like I know the command:

 
SwapMouseButton(true);


Swaps mouse buttons. But is there one to left click, or click and hold?

Trying to think of a better way to explain this.
I am a beginner and can't help you, but that is a really cool idea. You look like you are using windows.h functions, but I have never used one that calls a mouse event. Only ever used ones that check to see if there was a mouse event.

You could repost this on the windows programming forum and ask if anyone knows of a windows-dependent function that could do something like this, but there might be experienced programmers there who think it's ludicrous to take over user input.

Best of luck, sorry I couldn't help.
there's something called autoit that's made for this. It does key and mouse input.
Zippo88 then that would take away the learning experience.
closed account (2UD8vCM9)
Like zippo said, a scripting language like autoit is much more effective at something like this for the work put into it.
I realize that but I didn't think it would be hard to make c++ perform a left click lol.

I can already make the mouse go where I need it to go through c++.

What game do you plan on cheating at? Lol.
maxDaniels no game. I have integrity.

And for anyone in the future who wants the answer to my question I figured it.

This causes the double click that I needed.

1
2
3
4
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Here's the full code I use for double clicking and doing what I need.

When I'm done it should do what I need. Thanks to everyone who helped.

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

using namespace std;

int main()
{
	FreeConsole();

	int i, x, y;

	{
		x = 1000;
		y = 1000;
		SetCursorPos(x, y);
		Sleep(1);
	
	}

	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
You need to send the proper mouse events to the target window.

So, when you start the program, use CreateProcess(). Make sure to get the PROCESS_INFORMATION for the new program.

Next, you want to find the window. You'll need to use EnumWindows() and GetWindowThreadProcessId().

Finally, you'll need to either PostMessage() or SendMessage() (depending on your needs -- whether or not you'll want to wait) to put the proper mouse messages in the window's event queue.

The mouse messages you want are WM_MOUSEMOVE, WM_LBUTTONDOWN, and WM_LBUTTONUP.

Good luck now!
Thanks Duoas I will look into it.

One more thing though please.

The code I posted above you, worked for me like a charm. But, I don't understand what the 4 zeros mean after it.

Like: mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);

I tried without the zeros and it wouldn't run. Can someone please explain why the zeros are there?

Other than that I'm all set.

Thanks again,

-Irhcsa
Have you tried reading the documentation?

http://www.google.com/search?btnI=1&q=msdn+mouse_event
Topic archived. No new replies allowed.