I'm trying to write a small win32 application (in C or C++) that sends pre-cooked keystrokes to another application. The user experience should be this:
The user works with application X (which can be anything), then uses the mouse to click somewhere in the window belonging to application Y (written by me), which is visible on the screen. Application Y uses SendInput to send keystrokes to application X.
The problem is: SendInput sends keystrokes to the foreground window. How can application Y determine which window was the foreground window immediately before it received the mouse click?
Back in 1997, someone asked a similar question here (http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_10010231.html
), and the answer was to look at the wparam of the WM_SETFOCUS message. However, the answer was later withdrawn (and in Vista that parameter appears to always be 0). One of the last comments on the question from 1997 says: "It seems there is no way to obtain handle of deactivated window."
Is that really true?