如何从 c++ 发送双击键盘聚焦对象?

发布于 2024-10-21 01:56:20 字数 152 浏览 6 评论 0原文

问题是如何向已经通过键盘聚焦的对象发送双击?例如,假设我的鼠标位于屏幕右下角位置,如果我按 WIN+E 打开资源管理器,然后按 SPACE -> 。我将焦点转移到磁盘(例如 c:\ 磁盘),所以我想知道可以向其发送双击的焦点在什么坐标上。 C++中有没有什么函数可以帮我们做到这一点?

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 example), 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

-柠檬树下少年和吉他 2024-10-28 01:56:20
  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); 

来自谷歌:

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

  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

别在捏我脸啦 2024-10-28 01:56:20

我不确定这是否可能 - 在您的示例中,资源管理器窗口突出显示驱动对象 - 您需要某种方法来获取资源管理器窗口中对象的坐标(您无法控制,对吧?)

它不是很难向窗口发送双击 - 但窗口内发生的情况很难确定。

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.

怪我闹别瞎闹 2024-10-28 01:56:20

您可以使用GetFocus函数找到当前聚焦的窗口。但通常无法找到发送双击事件的位置。您可以使用GetWindowRect函数轻松找出任何窗口的尺寸和屏幕坐标。您可以将该事件发送到窗口的中心或其任何角落或其他任何地方,在某些情况下这就足够了。

在您的示例中,您需要弄清楚所选元素位于屏幕上的位置,并且该元素不是窗口,其状态由父窗口维护,通常无法获取该信息。

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.

狼性发作 2024-10-28 01:56:20

查看 MSDN 上的 MSAA 或 UIAutomation;这些 API 允许您访问 HWND 级别以下的元素信息。它们是为需要此信息的测试工具和辅助工具而设计的。例如,屏幕放大器可以使用这些 API 来跟踪键盘焦点、获取当前元素的位置,并确定要放大的正确坐标。

MSAA/UIA 在 Windows 中得到广泛支持 - 所有系统控件(如资源管理器中使用的)都支持它,IE、Firefox 和其他一些应用程序的内容也是如此。

您可以使用Windows SDK 中的inspect.exe 工具来使用此功能。

请注意,在单击目标之前,您应该检查该点的元素是否是您期望的元素:如果中间有其他对话框,则单击将转至该元素。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文