In my C # .Net application, I am trying to get the selected text in the current window. (Note that this can be any window open in windows, such as a word or safari).
I can get a handle to the current focused control. (Using multiple interop calls for user32.dll and kernel32.dll).
However, I was not able to consistently return the selected text.
I tried to use SENDMESSAGE and GET_TEXT. However, this only works for some applications (works for simple applications such as wordpad, does not work for more complex applications such as firefox or word).
I tried to use SENDMESSAGE and WM_COPY. However, again, this only looks like some controls. (I would have thought that WM_COPY would lead to the same behavior as manually pressing CTRL-C, but that is not the case).
I tried using SENDMESSAGE and WM_KEYUP + WM_KEYDOWN to manually stimulate the copy command. BUt this does not work either. (Possibly overlapping with the actual hotkey pressed by the user to call my applications).
Any ideas on how to get the current text? (in any application).
source
share