Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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.
 

 
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 26-Sep-12 20:41pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks for your quick reply
I'll try your suggestion and give your feedback later.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 315
1 Jochen Arndt 190
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100