Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 打开窗口时system.windows.forms.sendkeys.sendwait不工作_C#_Sendkeys - Fatal编程技术网

C# 打开窗口时system.windows.forms.sendkeys.sendwait不工作

C# 打开窗口时system.windows.forms.sendkeys.sendwait不工作,c#,sendkeys,C#,Sendkeys,我正在使用SendKeys.SendWait向其他正在运行的应用程序发送击键。但是,如果目标应用程序不是最小化的,它就不起作用。这个方法有什么问题吗?向正在运行的应用程序发送击键的其他方法有哪些 我正在使用的代码块: SetForegroundWindow(handleToApplication); System.Windows.Forms.SendKeys.SendWait(Keystroke); 我建议在发送键之前操作窗口 private void setW

我正在使用SendKeys.SendWait向其他正在运行的应用程序发送击键。但是,如果目标应用程序不是最小化的,它就不起作用。这个方法有什么问题吗?向正在运行的应用程序发送击键的其他方法有哪些

我正在使用的代码块:

SetForegroundWindow(handleToApplication);            
System.Windows.Forms.SendKeys.SendWait(Keystroke);

我建议在发送键之前操作窗口

    private void setWindowState(string windowTitle, int option)
    {
        /**
        SW_HIDE             0
        SW_SHOWNORMAL       1
        SW_NORMAL           1
        SW_SHOWMINIMIZED    2
        SW_SHOWMAXIMIZED    3
        SW_MAXIMIZE         3
        SW_SHOWNOACTIVATE   4
        SW_SHOW             5
        SW_MINIMIZE         6
        SW_SHOWMINNOACTIVE  7
        SW_SHOWNA           8
        SW_RESTORE          9
        SW_SHOWDEFAULT      10
        SW_FORCEMINIMIZE    11
        SW_MAX              11
        **/

        Process[] plist = Process.GetProcesses();
        IntPtr handle = new IntPtr();

        foreach (Process x in plist)
        {
            if (x.MainWindowTitle == windowTitle)
            {
                handle = x.MainWindowHandle;
                break;
            }
        }

        ShowWindow(handle, option);
    }

我建议在发送键之前操作窗口

    private void setWindowState(string windowTitle, int option)
    {
        /**
        SW_HIDE             0
        SW_SHOWNORMAL       1
        SW_NORMAL           1
        SW_SHOWMINIMIZED    2
        SW_SHOWMAXIMIZED    3
        SW_MAXIMIZE         3
        SW_SHOWNOACTIVATE   4
        SW_SHOW             5
        SW_MINIMIZE         6
        SW_SHOWMINNOACTIVE  7
        SW_SHOWNA           8
        SW_RESTORE          9
        SW_SHOWDEFAULT      10
        SW_FORCEMINIMIZE    11
        SW_MAX              11
        **/

        Process[] plist = Process.GetProcesses();
        IntPtr handle = new IntPtr();

        foreach (Process x in plist)
        {
            if (x.MainWindowTitle == windowTitle)
            {
                handle = x.MainWindowHandle;
                break;
            }
        }

        ShowWindow(handle, option);
    }