Pregunta

Is it possible to get the selected text of any window including non-UI automation elements? I want to be able to get the selected text of the current contents of the currently focused element of any process.

I've seen various examples of using UI automation to do this, but this only works with certain, what seems more recently developed applications in .NET. I need to be able to get the text of any window.

I remember a while back, an application which behaved like a dictionary, where you could hover over some text with the mouse anywhere in Windows and it would show a tooltip with the definition. Can this be achieved in C# & .NET?

I've been using WinSpy to inspect the contents of the window which doesn't seem to work with UIA, and the ApplicationId shows up as empty or "". I'm guessing that this particular element isn't supported by UIA. I've also noticed when I tested with Notepad++, that it uses Scintilla, which also doesn't seem to play with UIA.

Perhaps if someone could show a reliable way of doing this with some other method, I could use a hybrid approach to my app. Use the UIA framework, and if this doesn't yield results, then it drops back down to some other method.

¿Fue útil?

Solución

One simple way to achieve this is to send CTRL + C key code to the selected windows then you can find the selected text in clipboard. This is very easy to implement. See here for sending keys to other processes and here to read the clipboard. The drawback is that you lose the clipboard content obviously. If you search for a more solid solution check this question.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top