the question is how to send double click to object who is already focused by keyboard? For example let's say that my mouse is on bottom right position on screen, if i open explorer by pressing WIN+E, and than press SPACE -> i will get focus to disk (c:\ disk for e开发者_如何学Goxample), so i want to know on what coordinate is that focus that can send double click to it. Is there any function in c++ that do it for us?
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(10);
// Click Two
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
From google:
http://groups.google.com/group/borland.public.delphi.winapi/browse_thread/thread/f1380942baf5c1ae?pli=1
http://msdn.microsoft.com/en-us/library/ms646260(v=vs.85).aspx
I'm not sure that is possible - in your example, the Explorer window is highlighting the drive object - you need some way to obtain the coordinates of the object with in the explorer window (which you do not control, right?)
It's not hard to send a double-click to a window - but what is happening within the window is difficult to determine.
You can find currently focused window with GetFocus
function. But there's in general no way to find where to send a double click event. You can easily find out the dimensions and the screen coordinates of any window with GetWindowRect
function. You can send that event to the center of the window or to any of its corner or anywhere else, and in some cases that would suffice.
In your example you would need to figure out where the selected element is located on the screen and that element is not a window, its state is maintained by the parent window and generally there's no way to get that information.
Check out MSAA or UIAutomation on MSDN; these are APIs that allow you to access element information below the HWND level. They are designed for test tools and accessibility tools that need this information. For example, a screen magnifier can use these APIs to follow the keyboard focus, get the location of the current element, and determine the correct coordinates to zoom in on.
MSAA/UIA are supported widely within Windows - all the system controls (as used in explorer) support it, as does the content of IE, Firefox, and some other apps.
You can use the inspect.exe tool that's part of the Windows SDK to play with this functionality.
Note that before clicking on the target, you should check that the element at that point is the element you expect it to be: if there's some other dialog in the way, the click will go to that element instead.
精彩评论