views:

477

answers:

2

I am trying to send keystrokes to cmd.exe that I launch from my app. In doing so, I am able to send all the keyboard characters, but if I try to send Backspace, it doesnt seem to take effect. The following is the code snippet to send message to cmd.exe:

SendMessage((int)shell.MainWindowHandle, WM_KEYDOWN, ((int)e.KeyCode), 0);
SendMessage((int)shell.MainWindowHandle, WM_KEYUP, ((int)e.KeyCode), 0);

Any idea why this wouldnt work? What is the best way to send to the stdin of cmd.exe from a C# app?

thanks in advance

+1  A: 

You will have to P/Invoke SendInput() because Backspace is processed by the keyboard driver directly.

Gonzalo
A: 

use the ascii code: backspace --> OCT 0x10, char 'BS'

Sunrising
The problem with sendinput is that it requires the console app to be in the foreground. But I am actually keeping it hidden and capturing inputs and outputs to it. :(Also e.KeyCode was 0x8 that matches with the ascii code for BS
Murali