如何在 C# 中获取特定流程的焦点元素

发布于 2025-01-03 00:49:34 字数 278 浏览 1 评论 0原文

我陷入了我的问题,我已经调用了一个流程,现在我想要它的重点元素。

例如。我运行一个在 Google chrome 中打开的 www.google.com 进程 现在假设我想搜索“hello”,据我所知,执行此操作的方法是获取键盘焦点元素,该元素将成为 google.com 的文本框。那么如何通过我的应用程序(即以编程方式)执行此操作(获取键盘镀铬工艺的重点元素) Process[] pr = Process.GetProcessesByName("chrome"); var 目标 = pr[0];

im stuck in my problem, i have invoke a process and now i want its focused elements.

for example. i run a process www.google.com that opens up in Google chrome
now lets say i want to search "hello" the way of doing this as far as i know is to get the keyboard focus element that will be a textbox of google.com .so how to do that through my application i.e programmatically(getting keyboard focused element of chrome process)
Process[] pr = Process.GetProcessesByName("chrome");
var target = pr[0];

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

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

发布评论

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

评论(1

画骨成沙 2025-01-10 00:49:34

你的问题a有点模糊,所以我会尝试根据几种不同的解释给出一些指示:

1)如果你指的过程始终是一个网站,你应该跳过屏幕抓取技术,例如@vulkanino 提到过,只需直接获取网站内容即可。如果您必须获得由真实浏览器(而不是原始 HTML 本身)解析的网站,您可以使用屏幕抓取,但请记住,并非所有计算机都使用相同的浏览器。

2) 如果您想从正在运行的进程中屏幕抓取信息,您(不幸的是)没有像您期望的那样简单的 API,其中 Process pr 对象包含您想要的元素列表可以穿越。这是因为该流程可能是用 .NET/WinForms、.NET/WPF、C++/MFC 或工作方式截然不同的十几个其他 UI 框架中的任何一个编写的。

我建议使用屏幕阅读器辅助框架,例如 Microsoft 的 UI Automation,它能够从许多常见应用程序的 UI 中提取文本。此功能的存在是为了帮助视力不佳的人读出应用程序 UI,但也可用于屏幕抓取。

Your question a is a bit vague, so I'll try to give several pointers based on several different interpretations:

1) If the process you're referring to is always a web-site, you should skip the screen-scraping techniques, like @vulkanino mentioned, and simply fetch the contents of the web-site directly. If you must get the website as parsed by a real browser (rather than the raw HTML itself), you can use screen-scraping, but remember that not all computers use the same browser.

2) If you want to screen-scrape information from a running process, you (unfortunately) don't have a simple API like the one you expected, where the Process pr object contains a list of elements you can traverse. This is because the process might have been written in .NET/WinForms, .NET/WPF, C++/MFC or any of a dozen other UI frameworks that work very differently.

What I would suggest is using a screen-reader accessibility framework, such as Microsoft's UI Automation, which is able to extract text from the UI of many common applications. This functionality exists to help read out application UI for the hard of sight, but can be used for screen-scraping as well.

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