下面的 sendkeys 代码适用于记事本,但不适用于计算器。问题是什么?(与我在这里发送的来自 .NET 程序的 Sendkeys 问题相比,这是另一个问题)
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
private void button1_Click(object sender, EventArgs e)
{
IntPtr calculatorHandle = FindWindow("SciCalc", "Calculator");
//IntPtr calculatorHandle = FindWindow("Notepad", "Untitled - Notepad");
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
SetForegroundWindow(calculatorHandle);
System.Threading.Thread.Sleep(1000);
SendKeys.SendWait("111*11=");
//SendKeys.SendWait("{ENTER}");
//cnt++;
SendKeys.Flush();
}