Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get highlighted text from active window

Tags:

c#

winforms

I would like to know how can I get highlighted text from any window for example: (excel, ie, firefox,…). please note that the following message not work in the above application WM_GETTEXT,WM_COPY,EM_GETSELTEXT.

I have also tried control C (copy) and get selected text from clipboard but it is not a good idea.

Language used: C#

like image 731
Gaby Avatar asked Jan 13 '10 15:01

Gaby


1 Answers

I haven't tried it myself, but the Microsoft UI Automation API should have the functionality that you need.

The UI Automation API is what you would use if you were building a screen reader to assist blind people. So it should definitely be able to access the selected text in an arbitrary application.

A good place to start would be with the "Text Pattern Overview" at http://msdn.microsoft.com/en-us/library/ms745158.aspx

Also keep your eye on question 517694. I think you'll find that answers to that question will solve your problem.

like image 185
Antony Perkov Avatar answered Sep 16 '22 19:09

Antony Perkov