How to Mimick a user's keystrokes
I am trying to write a program that will eventually mimick a user. Basically, I need to somehow have my program automatically execute various keystrokes, but I am unsure how to do this. For example, when the user clicks a button, say "Hello", I want my program to switch programs by making the computer think the user hit alt+tab then I want it to type/paste the word "Hello" into the selected field of that program.
In other words, how would I write code that will, for lack of a better phrase, type predefined keys for the user?
Thanks for any help.