C# sendkeys to calculator
Posted
by user203123
on Stack Overflow
See other posts from Stack Overflow
or by user203123
Published on 2010-04-09T03:12:25Z
Indexed on
2010/04/09
3:13 UTC
Read the original article
Hit count: 502
The sendkeys code below works well for Notepad but it doesn't work for Calculator. What is the problem? (It's another problem compared to what I sent here http://stackoverflow.com/questions/2604486/c-sendkeys-problem)
[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();
}
© Stack Overflow or respective owner