tags:

views:

164

answers:

2

I am developing a .NET windows app that needs to insert text in the place where the cursor is. The cursor will be in a different application that I have no control over. I think the operating system needs to be used here to achieve this. Can you help please?

+2  A: 

Put the text you want to insert into the clipboard

Find the window's handle:

Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process p in processes)
{
    IntPtr pFoundWindow = p.MainWindowHandle;
    // Do something with the handle...
}

Send a "Ctrl+V" message to the window using pinvoke, see http://www.pinvoke.net/default.aspx/user32.SendMessage

Catalin DICU
pinvoke.net is down at the moment :( This sounds pretty cool, I'd like to try it myself.
BFree
A: 

The most easy is to use the SendKeys class on Windows.Forms.

Otherwise use the SendMessage from the windows api to send key by key (some information on this).

Do not use the clipboard, the user typically does not want that, and does not expect that.

GvS