Going in for such things is apparently the bad business. There is no an universal reliable way of doing such tricks; you can do it for one specific application, but that method won't work for others. Notably, if you can access some control and get its text by using raw Windows API based on Windows messaging mechanism, it won't work for WPF applications, which are based on Direct X and participate in windows message pumping only on the very top level of the window, while internal life of events controlling UI elements remains totally non-transparent to Windows API.
With the global Windows Hook, you of course can perfectly simulate input devices and hence input to any kinds of applications. It cannot help you to get data from those applications, such as selected text or anything like that.
And I cannot see truly legitimate reasons to do such things. This is not how real programming work.
Software engineering is done by writing code, not by hacking other applications. If you want, call it "integration", but for the applications not specially designed for "integration" this is hacking. If you think about it — quite counter-productive activity, waste of time.
[EDIT]
Here is the thing: before,
you did not mention that you merely wanted to get selected text in the system keyboard. Thank you for clarification in your comment below.
This is of course quite possible and actually easy enough. All you need is to use the raw Windows API
SendInput
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^].
With .NET, you need to use P/Invoke to do it, but this is already done for you. Here:
http://www.pinvoke.net/default.aspx/user32.sendinput[
^].
You can simply simulate the press to Ctrl+A (select all) Ctrl+C or Ctrl+Insert, or anything you need to get.
(For a record: to me, it will still remains a hack, even though it is very easy. This is not how real software engineering is done.)
—SA