SendKeys Ctrl-A not working

ALI picture ALI · Aug 7, 2010 · Viewed 55.9k times · Source

I'm trying to send CTRL A (select all to an app in this case word but try as I might it doesn't work) I've tried quite a few combinations but all to no avail, any ideas?

        IntPtr appHandle = FindWindow(null, "Document1 - Microsoft Word");
        if (appHandle == IntPtr.Zero)
        {
            MessageBox.Show("Specified app is not running.");
            return;
        }

        SetForegroundWindow(appHandle);
        System.Threading.Thread.Sleep(500);

        //SendKeys.SendWait("111");
        SendKeys.SendWait("^A");
        //SendKeys.SendWait("^(A)"); //ctrl a
        //SendKeys.SendWait("(^A)");

Answer

Chola picture Chola · Jul 31, 2012

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use +(EC). To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use +EC.

Answer is:

SendKeys.Send("^(a)");