Reputation: 1545
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?
Upvotes: 0
Views: 857
Reputation: 22020
You can SendMessage
to whatever window you want, even on other processes. You can even use HWND_BROADCAST
to 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 SendInput
is 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 using SendInput
, you'll have to loop over the list of windows, and for each window first set the focus and then send the input.
Upvotes: 1
Reputation: 612794
What you describe, faking input, is implemented by the SendInput function. Input goes to the thread which has input focus.
Upvotes: 5