1

In C# with VS 2012 is it possible to "read" what a user highlights in another program?

For instance if a user is running Firefox, and uses the mouse to select (or highlight) a piece of text, can a program built with C# be "aware" of this selected text?

I have searched around, but I have come up empty.

Reid
  • 4,376
  • 11
  • 43
  • 75
  • 1
    I have a strong feeling you're asking the wrong question. What are you trying to actually DO with that text? – Stu Jul 25 '12 at 19:16
  • Multiple tasks: TTS, Storing, and Organizing. I would like this to be done in the background as much as possible as to not intrude on the users experience. Mainly I am trying to create a TTS program for myself so I can read long articles better, and organize my thoughts while doing so (im dyslexic). Please not that I do not intend distribute this program, so I am not worried about the legality of doing the actions of reading text from another program. – Reid Jul 25 '12 at 19:22
  • It should also be noted that I am currently in the "brainstorming" phase of this program, and I would be open to any suggestions about workarounds. --Thanks! – Reid Jul 25 '12 at 19:24
  • You might want to go for the add-on route instead. Does this help? http://stackoverflow.com/questions/4712310/javascript-how-to-detect-if-a-word-is-highlighted – Stu Jul 25 '12 at 19:25
  • I would like this to work in "any" program. I often find my self reading things from pdf's to email, to the internet, to code documentation. But this is probabably the route I will go if I can not find another option. – Reid Jul 25 '12 at 19:27
  • Ah, you'll want to start here then: http://msdn.microsoft.com/en-us/library/windows/desktop/bb735024.aspx -- C# might not be the best tool for the job though. – Stu Jul 25 '12 at 19:33

1 Answers1

1

I think the easiest way to do this is copying the text to the clipboard. For example, call CTRL+C programmatically. It will work for almost every program. If you need a certain program, you can do it using the UI Automation.

Alex Butenko
  • 3,664
  • 3
  • 35
  • 54