Or to clarify this question, how can I make Windows think I hit a key, when I really didn’t? I know I could possibly use SendMessage and specify the input there, but then wouldn’t only my application receive it? I’d like control to the extent of all applications receiving the “fake” input. Any advice?
Share
You can
SendMessageto whatever window you want, even on other processes. You can even useHWND_BROADCASTto send it to every to-level window on the system. But is that what you really want? If you’re only interested in a specific program, you can get its window’s handle using FindWindow, and then send the message only to that window.Note that if all you want to do is a simple keystrokes injection into another process, then
SendInputis indeed the way to go. If you’d like to send some global keyboard shortcut it doesn’t matter who has the focus. If you’d like to send the same input to more than one window usingSendInput, you’ll have to loop over the list of windows, and for each window first set the focus and then send the input.