How do I make the program simulate a double click?

Started by
11 comments, last by hellfire 21 years, 8 months ago

  SetCursorPos(PosX, PosY);SendMessage(WindowHandle, WM_RBUTTONDBLCLK, MK_RBUTTON, (LPARAM)MAKEWORD(PosX, PosY));  


I haven''t tested this, but that''s my best guess

Crispy;
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
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);

Header: Declared in winuser.h.
Import Library: Use user32.lib.

I think this will work, I used it along time ago to do something similar, You can also use it to move the cursor around too.

Just tested this out and a few things I wanted to point out...This does not tie the messages to any window, it's just like if YOU doubleclicked...where ever the cursor is, it will double click it (start button, taskbar, any window)...it puts them into the system messages which windows will pass along to the window under the cursor.

[edited by - dabx11 on July 26, 2002 11:02:53 PM]
I haven't tried this, but i think it might work OK. Just look out for teh SendMessage() function. Me thinks i didn't use it corectly.


      	int Width = 512,	//Set the window width and height	    Height = 512;	int DistanceToControl = 10000;		//the distance in pixels to the desired control.	//I made this number up.  So, it might not be right :)		int Centerx = Width\2,	//Setting it to the center	    Centery = Height\2;	SetCursorPos(Centerx, Centery);	//Guess.	Sleep(500);/*Lets pause so we can 		   give the user a chance 		   to realize he has no control*/		/*In the loop below i am assuming the control to be 	in a direct 45 degree diagonal with the center	of the screen. If it isn't, you will need to 	change the angle by adjusting the change in 	x and y.*/	for (int i = 0; i < DistanceToControl, i++)		{		Centerx-=1;		Centery-=1;		SetCursorPos(Centerx, Centery);		Sleep(250);/*Going to sleep so the cursor doesn't fly				   to the control.  Sleep(...) Takes Milliseconds,				   so we are pausing for 1/4 of a second between each				   iteration of the loop.  Not the best way, but its easy :)*/	}	SendMessage(hWnd,WM_LBUTTONDOWN,0,0);	/*I'm not sure i am using this corectly, so you might want	to check some docs about it.  But essentialy the logic	is that we send your program a click event,	and if i am thinking correctly, it should do everything 	else that it was supposed to.*/      



[edited by - MrBeaner on July 26, 2002 8:13:26 PM]
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.

This topic is closed to new replies.

Advertisement