Search code examples
c#legacy

C# SendKey to MS-DOS Application


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?


Solution

  • 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.