You need to P/Invoke only one Windows API:
SendInput
. It provides comprehensive simulation of all mouse and keyboard input exactly as the user and device drivers would do.
I assume you know how to do P/Invoke.
[EDIT]
Just a side note:
Consider improving your event handling technique. This would be more maintainable (but if you like my technique you should not create events using Designer; I still think its better:
MyButton.Click += (sender, eventArgs) => {
DoWhateverYouWant();
};
Also note that
Apply_Click
violates (good) Microsoft naming conventions.
Here is my explanation why such technique is better the code is more maintainable:
[Solved] How to add Event for C# Control[
^].
See also:
how to call keydown event on particular button click[
^].
—SA