按特定过程的键

Press key to a specific process

我想写一个可以在不同进程上按键的小应用程序。 不同的进程是一个控制台应用程序 - 但我想在隐藏模式下 运行 它并专门模拟 "Pause/Break" 按键(就像它被聚焦并且我手动按下暂停键一样)

我找到了这些例子: How can I programmatically generate keypress events in C#? How to simulate key presses on a specific application

但我认为他们无法帮助解决我的情况(或者我错了?)

至于编程语言 - 我不太关心 - (c#/c++/c/python/ruby - 什么都行)

我相信您将流程存储在一些 variables/handlers 中。

您需要做的就是获取进程的输入流,然后将您想要的密钥发送到 pass/press 以用于特定进程。

您的代码应如下所示:

    Process p = new Process(); //your process
    string key = "A"; //character or string that you want to press
    p.StandardInput.Write(key);

其中'P'是进程,key是按下的键

希望对您有所帮助!