如何将功能按键 (F1..F12) 发送到 .NET 中的控制台应用程序

发布于 2024-09-07 04:27:57 字数 309 浏览 2 评论 0原文

我正在用 C# 编写一个窗口化的 .NET 应用程序,它通过 Process 类运行第三方控制台应用程序,尽可能隐藏(CreateNoWindow、RedirectStandardOutput 等)。

我已将其重定向为 StandardInput,因此我可以编写我想要的任何字符串,但不能编写功能键或其他类型的特殊键,因为它们没有字符表示形式。对于我来说,我必须将 F1 到 F4 键发送到控制台应用程序。我找到的解决方案适用于窗口应用程序(PostMessage、SendMessage)。

如何为我的控制台应用程序执行此操作?

与进程句柄有什么关系吗?

I am writing a windowed .NET app in C#, which runs a third party console application via the Process class, as hidden as possible (CreateNoWindow, RedirectStandardOutput, etc.).

I've redirected it's StandardInput, so I can write whatever string I want, but not function keys or other type of special keys, as they don't have a character representation. As for me, I have to send keys F1 to F4 to the console app. The solutions I've found are for windowed app (PostMessage, SendMessage).

How can I do this for my console application?

Is there anything to do with the Handle of the Process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

表情可笑 2024-09-14 04:27:57

Sendkeys.SendWait 可能会解决您的问题问题。

Sendkeys.SendWait may solve your problem.

她比我温柔 2024-09-14 04:27:57

你不能。功能键无法与标准输入一起使用,应用程序必须调用 ReadConsoleInput() 才能检测到它们。当您在没有控制台窗口的情况下启动进程时,这不再有效。

You can't. Function keys cannot work with stdin, an app has to call ReadConsoleInput() to be able to detect them. That no longer works when you start the process without a console window.

时光礼记 2024-09-14 04:27:57

是否 SendKeys 工作("{F1}")? (不过,控制台必须处于活动状态)。

Does SendKeys work ("{F1}")? (the console will have to be active, though).

心清如水 2024-09-14 04:27:57

这并不是直接回答您的问题,但您是否考虑过使用 MSMQ?

如果您的窗口应用程序可以接收这些按键,它可以使用 MSMQ 将该事实传递到您的控制台应用程序。您可能不必实际传递按键,只需传递它们被按下的事实即可。

我发现了这个 techrepublic 文章 有助于了解 MSMQ 的基础知识。

This isn't directly an answer to your question, but have you considered using MSMQ?

If your windowed application can receive those key-presses, it could pass that fact on to your console application using MSMQ. You may not have to actually pass the key-press, just the the fact that they were pressed.

I have found this techrepublic article helpful in getting the basics of MSMQ working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文