How to send Ctrl/Shift/Alt + Key combinations to an application window? (via SendMessage)

后端 未结 5 646
日久生厌
日久生厌 2021-02-13 18:24

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+

5条回答
  •  误落风尘
    2021-02-13 18:56

    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.

提交回复
热议问题