I can successfully send any single key message to an application, but I don't know how to send combinations of keys (like Ctrl+F12, Shift+F1, Ctrl+R, etc..)
Tried doing it this way:
SendMessage(handle, WM_KEYDOWN, Keys.Control, 0);
SendMessage(handle, WM_KEYDOWN, Keys.F12, 0);
SendMessage(handle, WM_KEYUP, Keys.F12, 0);
SendMessage(handle, WM_KEYUP, Keys.Control, 0);
but this does not seems to work (application acts like only F12 is pressed, not Ctrl+F12).
Any ideas how to make this work?
You would probably find that using SendInput (documentation here) works a lot better. You will need to P/Invoke it from C#, example here. You can provide arrays of data with keys down and up and properly set the other message parameters, for example whether left or right Ctrl/Shift/Alt were pressed.
You can also use the SendKeys
class (documentation here). This allows you to specify keys by name, e.g., {^F12}
for Ctrl+F12.
Edit: The OP is now saying he needs to send input to minimized applications without activating them. This is not possible to do reliably in any way, including even with specialized hardware. I've worked in automation. It just isn't possible. The OP needs to use FindWindow
/SetForegroundWindow
to toggle the target app on, and then he can toggle back to his application.