[英]How do I programmatically press Enter?
I have a C# console program which starts calculator and simulates key presses. 我有一个C#控制台程序,它启动计算器并模拟按键。 How do I programmatically press Enter ? 如何以编程方式按Enter键 ?
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// Send a series of key presses to the Calculator application.
private void StartCalculator()
{
Process.Start("calc.exe");
IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
if (calculatorHandle == IntPtr.Zero)
{
return;
}
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
SendKeys.SendWait(" ");//how press enter?
}
Taken from SendKeys.Send Method 取自SendKeys.Send方法
SendKeys.SendWait("~"); // How to press enter?
or 要么
SendKeys.SendWait("{ENTER}"); // How to press enter?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.