Simulating Input

I wrote a program in C++ that will activate a macro when a specific key is pressed. It simulates the actions using SendInput() in <windows.h>. The downside to this is that while the macro is running, the user cannot perform any actions because they must wait for the macro to finish. Instead of simulating these key events globally through windows, is there a way to send the input to the specific application so that this macro would run accordingly with its accompanying application even when it is out of focus or minimized? This would allow the user to do other things on the computer without waiting for the macro to finish execution.
Example: Have notepad minimized and when the program is run, it simulates typing in notepad. The user could then maximize notepad and see that text has been written in it.

(Not the most efficient way to simulate a click but this is how I wrote it:)
SendInput(1, &ip, sizeof(INPUT));
SendInput(1, &ip, sizeof(INPUT));
You can use the FindWindow() function of the windows api:

and then PostMessage():

It's not that easy though
Topic archived. No new replies allowed.