C# 打开窗口时system.windows.forms.sendkeys.sendwait不工作
我正在使用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
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);
}