Search code examples
c#.netwindowssendkeys

How to send Ctrl+S through SendKeys.Send() method to save a file in an external application?


I need to save a file which is in an external application using SendKeys.Send() method. The keys needed to be sent are Ctrl+S.

I wrote the below code, but it does not work:

SendKeys.SendWait("^%s?");  // to get the Save As dialog
Thread.Sleep(5000);
SetForegroundWindow(FindWindow(null, "Save As"));
Thread.Sleep(5000);
SendKeys.SendWait("xyz"); // Sending FileName

Solution

  • I believe you need to use:

    SendKeys.SendWait("^(s)");
    

    Instead of:

    SendKeys.SendWait("^%s?");
    

    Have a look at https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(v=vs.110).aspx for more information.