<tfoot id='KOjhu'></tfoot>
<legend id='KOjhu'><style id='KOjhu'><dir id='KOjhu'><q id='KOjhu'></q></dir></style></legend>
    <bdo id='KOjhu'></bdo><ul id='KOjhu'></ul>

    1. <i id='KOjhu'><tr id='KOjhu'><dt id='KOjhu'><q id='KOjhu'><span id='KOjhu'><b id='KOjhu'><form id='KOjhu'><ins id='KOjhu'></ins><ul id='KOjhu'></ul><sub id='KOjhu'></sub></form><legend id='KOjhu'></legend><bdo id='KOjhu'><pre id='KOjhu'><center id='KOjhu'></center></pre></bdo></b><th id='KOjhu'></th></span></q></dt></tr></i><div id='KOjhu'><tfoot id='KOjhu'></tfoot><dl id='KOjhu'><fieldset id='KOjhu'></fieldset></dl></div>

        <small id='KOjhu'></small><noframes id='KOjhu'>

      1. 如何将密钥而不是字符发送到进程?

        How to send keys instead of characters to a process?(如何将密钥而不是字符发送到进程?)

      2. <small id='EXcUh'></small><noframes id='EXcUh'>

          <legend id='EXcUh'><style id='EXcUh'><dir id='EXcUh'><q id='EXcUh'></q></dir></style></legend>

              1. <i id='EXcUh'><tr id='EXcUh'><dt id='EXcUh'><q id='EXcUh'><span id='EXcUh'><b id='EXcUh'><form id='EXcUh'><ins id='EXcUh'></ins><ul id='EXcUh'></ul><sub id='EXcUh'></sub></form><legend id='EXcUh'></legend><bdo id='EXcUh'><pre id='EXcUh'><center id='EXcUh'></center></pre></bdo></b><th id='EXcUh'></th></span></q></dt></tr></i><div id='EXcUh'><tfoot id='EXcUh'></tfoot><dl id='EXcUh'><fieldset id='EXcUh'></fieldset></dl></div>
                  <tbody id='EXcUh'></tbody>
                <tfoot id='EXcUh'></tfoot>

                • <bdo id='EXcUh'></bdo><ul id='EXcUh'></ul>

                  本文介绍了如何将密钥而不是字符发送到进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  System.Diagnostics.Process 公开了一个名为 StandardInput 的 StreamWriter,据我所知,它只接受字符.

                  System.Diagnostics.Process exposes a StreamWriter named StandardInput, which accepts only characters as far as I know.

                  但我也需要发送击键,有些击键不能很好地映射到字符.

                  But I need to send keystrokes as well, and some keystrokes don't map well to characters.

                  我该怎么办?

                  推荐答案

                  您正在将输入流与控制信号混合.如您所知,控制台进程有一个默认输入流,您可以使用 StandardInput 控制该输入流.但是 Ctrl-C 和 Ctrl-Break 不是通过此流发送到进程的字符,而是进程使用注册的信号处理程序接收的控制信号,请参见 CTRL+C 和 CTRL+BREAK 信号:

                  You are mixing input streams with control signals. A console process has a default input stream which you can control with the StandardInput, as you already know. But Ctrl-C and Ctrl-Break are not characters sent to the process through this stream, but instead they are instead control signals that the process receives using the registered signal handlers, see CTRL+C and CTRL+BREAK Signals:

                  默认情况下,当控制台窗口有键盘焦点,CTRL+C 或CTRL+BREAK 被视为信号(SIGINT 或 SIGBREAK) 而不是键盘输入.

                  By default, when a console window has the keyboard focus, CTRL+C or CTRL+BREAK is treated as a signal (SIGINT or SIGBREAK) and not as keyboard input.

                  要向进程发送虚假信号,您可以使用 GenerateConsoleCtrlEvent 并发送 CTRL_C_EVENTCTRL_BREAK_EVENT.此 API 没有 .Net 等效项,因此您必须 PInvoke 它.

                  To send fake signals to a process you can use GenerateConsoleCtrlEvent and send either CTRL_C_EVENT or CTRL_BREAK_EVENT. This API has no .Net equivalent, so you have to PInvoke it.

                  要在 .NET 中使用它,您只需包含函数定义:

                  To use it from .NET you simply need to include the function definition:

                  const int CTRL_C_EVENT = 0;
                  const int CTRL_BREAK_EVENT = 1;
                  
                  [DllImport("kernel32.dll")]
                  static extern bool GenerateConsoleCtrlEvent(
                      uint dwCtrlEvent,
                      uint dwProcessGroupId);
                  

                  这篇关于如何将密钥而不是字符发送到进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                  <i id='WIqer'><tr id='WIqer'><dt id='WIqer'><q id='WIqer'><span id='WIqer'><b id='WIqer'><form id='WIqer'><ins id='WIqer'></ins><ul id='WIqer'></ul><sub id='WIqer'></sub></form><legend id='WIqer'></legend><bdo id='WIqer'><pre id='WIqer'><center id='WIqer'></center></pre></bdo></b><th id='WIqer'></th></span></q></dt></tr></i><div id='WIqer'><tfoot id='WIqer'></tfoot><dl id='WIqer'><fieldset id='WIqer'></fieldset></dl></div>
                    <bdo id='WIqer'></bdo><ul id='WIqer'></ul>

                      1. <legend id='WIqer'><style id='WIqer'><dir id='WIqer'><q id='WIqer'></q></dir></style></legend>
                      2. <tfoot id='WIqer'></tfoot>
                            <tbody id='WIqer'></tbody>

                          <small id='WIqer'></small><noframes id='WIqer'>