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: 505

Filed under:
|

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

Related posts about c#

Related posts about sendkeys

  • .NET sendkeys to calculator

    as seen on Stack Overflow - Search for 'Stack Overflow'
    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… >>> More

  • C# sendkeys to calculator

    as seen on Stack Overflow - Search for 'Stack Overflow'
    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… >>> More

  • Cisco Configuration backup with Windows Script.

    as seen on Server Fault - Search for 'Server Fault'
    We have a client with a lot of Cisco Devices and we would like to automate the backups of these devices through telnet. We have both 2003 and 2008 servers and ideally use tftp to back it up. I wrote this: Set WshShell = WScript.CreateObject("WScript.Shell") Dim fso Set fso = CreateObject("Scripting… >>> More

  • C# sendkeys problem

    as seen on Stack Overflow - Search for 'Stack Overflow'
    THe code below I copied from MSDN with a bit of modification: [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); DllImport("User32")] public static extern bool SetForegroundWindow(IntPtr hWnd); int cnt = 0; private… >>> More

  • Sendkeys problem from .NET program

    as seen on Stack Overflow - Search for 'Stack Overflow'
    THe code below I copied from MSDN with a bit of modification: [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); DllImport("User32")] public static extern bool SetForegroundWindow(IntPtr hWnd); int cnt = 0; private… >>> More