Hi,

My application runs in the background, reads data from the COM port and it is supposed to output it to any program that currently has focus. So if it reads "hello world" from the COM port, and Notepad is open, then "hello world" is immediately printed in the document. If Firefox has focus, and the focus is on a text field, then the text field is filled with "hello world".

Getting the data from the COM port was the easy part. I don't know how to send the text to the foreground application. Here's what I tried:
1. Process.GetProcesses() with Win32 API GetForegroundWindow(). I would get the handle of the foreground process, match it with a process from GetProcesses() and write to its input stream (use the StandardInput member of process). However, it turns out, you cannot write to another process' input stream, unless you start that process yourself - which doesn't apply to my case.
2. Win32 API SendInput() - I can't figure this out: I'm looking at the method signature and I can't see a way to send the input to a specific process. How would I send it to the process that has the focus?
3. Win32 API CreatePipe(). This seems a little bit difficult, but I guess I might not have another choice.

Any suggestions?

Thanks,
Tiberiu