从外部应用程序读取所有文本 [英] Read all text from external Application

查看:32
本文介绍了从外部应用程序读取所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# 中有一个热键窗口应用程序,我想要其他应用程序的聚焦窗口中的所有文本,如记事本、浏览器、命令窗口(cmd)、Turbo c++、Pascal 等.

I have a hotkey window application in C# and I want all the text from the focused window of other application on pressing hotkey like notepad, browser, command window(cmd), Turbo c++, Pascal etc.

所以有可能吗?

如果有人有想法,请帮助我提供代码示例.

If any one have idea please help me with code example.

我附上了屏幕截图.我想从这个窗口阅读文本.按热键时,我想阅读文本这是我的测试文本".

I have attach screen shot. I want to read text from this window. On pressing hotkey I want to read text "This is my test text".

推荐答案

自称为屏幕阅读器"(针对视障人士)的应用程序会做类似的事情.

Application that call themselves "Screen Reader" (for visually impaired people) do that kind of things, sort of.

他们使用旧的 MSSA(Microsoft Active Accessibility)API 和/或新的 UIAutomation API.

They use the old MSSA (Microsoft Active Accessibility) APIs and/or the new UIAutomation APIs.

使用这两个 API,如果您有一个主窗口"HWND,您就可以浏览制作应用程序的组件树.然后,您可以检索属性,例如文本"或名称"等.

With the two APIs, if you have a "Main Window" HWND, you can then browse the tree of the componants making the app. You can then retrieve properties, such as "Text" or "Name" and so on.

如果应用程序不支持 Accessive 技术,您会依赖具体情况的解决方案,这意味着最终会出现可怕的黑客攻击(如 API 挂钩)或更常规的方法(如 DLL 注入和在 JAVA 中使用 JNI 调用 API)案例).

If the application doesn't support Accessive technologies, you fall back on case by case solutions, which means eventually awful hacks (as APIs hooking) or more regular methods (as DLL injection and use of the JNI Invocation API in the JAVA case).

这篇关于从外部应用程序读取所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆