Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used the following codes to simulate the mouse click event automatically.
Some dialogs can work well, but some button with TBitBtn button that can be clicked and just the mouse move to button area and no any other action.



C#
x = rect.left * 65535/ GetSystemMetrics(SM_CXSCREEN);
y = rect.top * 65536 / GetSystemMetrics(SM_CYSCREEN);

::mouse_event(MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE, x+10, y+5, 0, 0);
				
				::mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
				::mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);


please help me how to figure out his issue??

Thanks
Posted

This function has been superseded by the function SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

I don't say it will solve your problem, but with this function I never had any problems.

Your problem sounds rather strange. I would rather believe that you have miscalculated the click location or some other detail, but you did not provide enough information to pinpoint the problem. You can generate something based on exact coordinates, use your method and run target test application (not the one simulating the click) under the debugger, to check the coordinate.

I also must note, just in case: if, by any chance, you are using the simulation to write regular UI, it would be great abuse. However, there are cases where the user input simulation is important, for example, playing keyboard/mouse macro, creation of UI testing systems, etc.

—SA
 
Share this answer
 
Thanks for your quick reply
I'll try your suggestion and give your feedback later.
 
Share this answer
 
INPUT input;
memset(&input, 0x00, sizeof(INPUT));

input.type = INPUT_MOUSE;
input.mi.dx = vecBtnCords[i].x+800;
input.mi.dy = vecBtnCords[i].y+500;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE;
input.mi.time = 0;

SendInput(1, &input, sizeof(INPUT));

input.mi.dx = 0;
input.mi.dy = 0;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP;
input.mi.time = 0;
SendInput(1, &input, sizeof(INPUT));

SendInput(1, &input, sizeof(INPUT));



But it still cann't work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900