Archived

This topic is now archived and is closed to further replies.

How do I make the program simulate a double click?

This topic is 5619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like a to create a program that shows how do to certin windows things by doning itself. Does anyone know how to make the mouse double click? or simulate a doubleclick in C++?

Share this post


Link to post
Share on other sites
Yeah, I have had the same problem... Except I was trying to make a programm where the user could record his/her mouse movements/clicks, then play them back... to preform common opperations quickly.. yeah, but I did find something at vbapi.com... it only sucseeded in moving the moyuse though... couldnt tell it to be clicked and stuff...

tazzel3d ~ dwiel

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hmm.. let''s see. Windows is a Message based system. The mouse has an event where it sends messages to the top level window when it has moved and when it has double clicked.

If there were only a way to send these messages that the mouse sends.

WM_RBUTTONDBLCLK

or

WM_LBUTTONDBLCLK

I know it seems more elaborate that just calling the function that is called when the WM_LBUTTONDBLCLK message is processed, but it works too.

Marvin, if you don''t know, don''t correct. Look up these messages if you don''t know what they are.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just use the PostMessage() proc to send your doubleclick messages. Right? I''m new to Windows programming but I think that will work.

Share this post


Link to post
Share on other sites
I imagine you could use SetCursorPos() to change the position of the pointer, then use PostMessage() to send a WM_LBUTTONDBLCLICK message to your application. That should work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
maybe we should spend less time programming and more time learning how to spell

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That wasn''t me! I wasn''t the one flaming about spelling!

goatc has the right idea though, and the AP before him

WM_RBUTTONDBLCLK

or

WM_LBUTTONDBLCLK

Share this post


Link to post
Share on other sites

  
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;

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites