How can I list all the active windows, select one of them and then send some text to it?

For example MSN messenger. Making it periodically send a set message.

Please help me

Matt