tags:

views:

676

answers:

2

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?

+1  A: 

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.

Shay Erlichmen
Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead.Tried to use SendInput and it works pretty well. Now it drives the DOS application seamlessly. Thanks.
david.healed
A: 

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.