如何从 C# 运行 交互式 RPG 应用程序?

How to run interactive RPG Application from C#?

我正在尝试从 C# 运行 交互式 RPG/MAPICS 程序。为此,我尝试通过 PCSWS.EXE 启动一个 .ws 文件并从 C# 向其写入输入。

模拟器启动得很好,但我似乎无法通过标准输入或 SendMessage 向它发送输入(我通过 SETTEXT 和 KEYDOWN 都试过了)。

我在这里做错了什么?我应该如何从 C# 启动交互式 RPG 程序?

public void LaunchRPGApp(Application program)
{
    var processInfo = new ProcessStartInfo("pcsws.exe")
    {
        WindowStyle = ProcessWindowStyle.Normal,
        Arguments = "\"C:\Program Files (x86)\IBM\Client Access\Emulator\Private\veflast1.ws\"",
        RedirectStandardInput = true,
        UseShellExecute = false,
    };
    var process = Process.Start(processInfo);

    SendTextToProcess(process, "f");//Try via SendMessage

    using (var sr = process.StandardInput)//Try via StdIn
    {
        sr.Write("f");//does nothing
        sr.Close();
    }
}

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
private void SendTextToProcess(Process p, string text)
{
    const int WM_SETTEXT = 0x000C;
    const int WM_KEYDOWN = 0x0100;
    const int F_KEY = 0x46;
    Thread.Sleep(500);
    var child = FindWindowEx(p.MainWindowHandle, new IntPtr(0), "Edit", null);
    SendMessage(child, WM_KEYDOWN, F_KEY, null);//does nothing
    SendMessage(child, WM_SETTEXT, 0, text);//does nothing
}

这里有一些东西可以尝试,我不是 C# 程序员,但我发现了这个 here

ProcessStartInfo startInfo = new ProcessStartInfo("pcsws.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;

startInfo.Arguments = "C:\Program Files (x86)\IBM\Client Access\Emulator\Private\veflast1.ws";
Process.Start(startInfo);

有关于 PCSWS.EXE here

的命令行参数的文档

找到解决方案 - VBScript 宏可能 运行 通过将“/M={macroName}”附加到参数来启动 PCSWS.EXE。请注意,宏必须存在于特定文件夹中。 然后宏使用 autECLSession.autECLPS.SendKeys.

发送击键

像这样:

public void LaunchRPGApp(Application program)
{
    MakeMacro(program);

    const string wsPathAndFilename =
        "C:\Program Files (x86)\IBM\Client Access\Emulator\Private\flast1.ws";
    var processInfo = new ProcessStartInfo("pcsws.exe")
    {
        Arguments = "{wsPathandFilename} /M=name.mac"
    };
    Process.Start(processInfo);
}

private void MakeMacro(Application program)
{
    var macroText = GetMacroText(program);//Method to get the content of the macro

    var fileName =
        $"C:\Users\{Environment.UserName}\AppData\Roaming\IBM\Client Access\Emulator\private\name.mac";

    using (var writer = new StreamWriter(fileName))
    {
        writer.Write(macroText);
    }
}