我需要通过 C# 中的 SendKey 驱动旧版 DOS 应用程序。 然而,我发现它不起作用。
来自 http://www.vbforums.com/showthread.php?t=39626,据我所知,SendKey 并不真正适用于 MS-DOS 应用程序。 当调用 SendKey 时,所有 MS-DOS 应用程序接收到的都是“\”。
不过,论坛指出 MSDN 文章 142819,它利用剪贴板将按键推送到MS-DOS 应用程序。 给出了 VB 示例,但我不知道如何将其转换为 C#。
有人有或知道用 C# 编写的类似示例可供我参考吗?
I need to drive a legacy DOS application through SendKey in C#. However, I found that it didn't work.
From http://www.vbforums.com/showthread.php?t=39626, I understand that SendKey doesn't really works on MS-DOS application. All MS-DOS application receives is "\" when SendKey is called.
However, the forum points to MSDN Article 142819, which utilizes Clipboard to push the keys into the MS-DOS application. An VB sample is given but I don't know how to translate it to C#.
Anyone has or know any similar example that is written in C# that I can refer?
发布评论
评论(2)
如果我正确理解问题,您可以尝试使用 Process .StandardInput 属性用于发送密钥。 要获取 Process 对象,您可以使用 GetProcessBy... 方法之一。
If I understand question correctly, you can try to use Process.StandardInput property to send keys. To obtain a Process object you can use one of GetProcessBy... methods.
您应该使用 keybd_event (pinvoke)。 您需要使用 SetForegroundWindow (pinvoke),然后调用它。
You should use keybd_event (pinvoke) instead. You will need to set the console window to be the foreground window using SetForegroundWindow (pinvoke) and then call it.