0

I am trying to automate a process using a third party program in a C# console application. After my program starts the third party application (wxPirs.exe) I would like to wait (Thread.sleep) for 5 seconds, and then I would like alt+f, down arrow, enter, enter to be entered in the third party program.
I can see this is easily accomplished using sendkeys in a forms application, but my application is console based and I would like for it to stay that way if at all possible. I have created this same program in python and there was a pynput function that I could pip install that was very easy to use. Is there anything like this in C# that I just haven't came across from my googling and reading documentation?
The code block this would go into is below:

static void unPirs()
{
    string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
    string unpackedPath = homePath + "\\XBLA_Unpacked\\";
    string wxPirsPath = homePath + "\\wxPirs.exe";

    var files = GetAllFiles(unpackedPath);

    foreach (var file in files)
    {
        Console.WriteLine(file);
        var process = Process.Start(wxPirsPath, "\"" + file + "\"");
        Thread.Sleep(7500);
        
        process.WaitForExit();
    }
GSerg
  • 76,472
  • 17
  • 159
  • 346
cmclark00
  • 15
  • 5
  • If it's a console app, read and write to stdout and stdin respectively. – fredrik Nov 12 '22 at 21:28
  • 1
    What exactly does "alt+f, down arrow, enter, enter" do? It sounds like you are opening the"File" menu and selecting some option. Rather than doing whatever it is through the "File" menu, it can probably be done programmatically instead. So what are you trying to do exactly? – Sweeper Nov 12 '22 at 21:28
  • Yes, it opens the file menu, selects extract all, and then selects the default extraction folder. Since this is a third party program that I have no control over I didn't think there would be any way to do that programmatically, but I am a total newbie so I could definitely be wrong – cmclark00 Nov 12 '22 at 21:31
  • Does this answer your question? [Why is SendKeys in C# not working for me?](https://stackoverflow.com/q/67414414/11683) – GSerg Nov 12 '22 at 21:31
  • See if this answers your question https://stackoverflow.com/a/74939988/3057246 – Vinod Srivastav Dec 28 '22 at 12:35
  • 1. If the `exe` is a `.net` exe you can refer it to your project and may call the file open function from there. 2. See if that `exe` support input parameters so that you can pass it when doing `Process.Start("exe",args)` 3. There is `SendKeys.Send()` using that you can send keystrokes 4. You can use `kebd_event` form API also to send keystrokes pls see https://stackoverflow.com/a/74939988/3057246 for reference. – Vinod Srivastav Dec 28 '22 at 13:07

0 Answers0