Mouse Clicker -
Simulating mouse clicks in windows

Windows is an event driven programming operating system. Messages are sent by applications and the Windows OS itself. Then Windows decides whether a message should be sent to a specific application. In the case of mouse clicks, mouse click events are created. When the system receives such a message it checks (base on the click's screen coordinates) which window should receive the message (this also called a hit test) and then places appropriate mouseup/mousedown/mousedbl messages in the application's message queue.

Our goal is to simulate mouse clicks just as they would happen if one simply clicked the mouse with the cursor at its current position. Our approach will be to place messages into the global Windows message queue. To achieve this, we will use the mouse_event() function. Refer to the example:

	POINT p;
	GetCursorPos(&p);
	mouse_event(MOUSEEVENTF_LEFTDOWN, p.x, p.y, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, p.x, p.y, 0, 0);

	if (dblclick) {
		mouse_event(MOUSEEVENTF_LEFTDOWN, p.x, p.y, 0, 0);
		mouse_event(MOUSEEVENTF_LEFTUP, p.x, p.y, 0, 0);
	}

For more detail on the mouse_event() refer to MSDN. Simulating other actions in Windows can be done in the same manner. MSDN is your friend.

md5sum: 233694e1275134a88bc09fc8a947ef0d  clicker-0.1.tar.bz2

"Our faces marked by toil, by deceptions, by success, by love; our weary eyes looking still, looking always, looking anxiously for something out of life, that while it is expected is already gone - has passed unseen, in a sigh, in a flash - together with the youth, with the strength, with the romance of illusions" - Joseph Conrad, Youth

Last update: Wednesday, 11th October, 2023
Copyright © 2001-2024 by Lukasz Tomicki