How to get selected text from an active application, without using a clipboard

前端 未结 2 1692
一向
一向 2021-01-17 03:07

What am I doing:

My main intent is to enable user friendly text to speech for personal use on Win 7. Approach should work in Google Chrome, VS and Ecl

相关标签:
2条回答
  • 2021-01-17 03:32

    If to expand a little on what Bugfinder said, Microsoft provider a UI Automation Framework to solve problems like the one you mentioned:

    In particular you can use the TextSelectionChangedEvent of TextPattern:

    The problem with this solution is that it only works on supported operating systems and applications - and not all support this.

    Your clipboard solution is acceptable for applications that do not provide a good automation interface. But for many applications the UI Automation Framework will work well and will provide you with a far better solution.

    0 讨论(0)
  • 2021-01-17 03:34

    MS provide accessibility tools that do cover what you're trying to do. If you take a look at documents about screen scraping. In short, every component is accessible in some manner, if you use some of the windows debugging tools you can get to see the component names/structures within. You can then use that, however, its complicated as most times you would need to be very specific for each application you intend to scrape from.

    If you manage to scrape you dont need to use the clipboard, as you can access the text property of the apps direct. Its not something I've had to do, hence, Ive no code to offer off the top of my head, but the term "screen scraping" should point you in the right direction.

    0 讨论(0)
提交回复
热议问题