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:)
INPUT ip = {INPUT_MOUSE};
ip.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
SendInput(1, &ip, sizeof(INPUT));
ip.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
SendInput(1, &ip, sizeof(INPUT));
bump
You can use the FindWindow() function of the windows api:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx

and then PostMessage():

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632590%28v=vs.85%29.aspx

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