How to send backspace using sendmessage(C#) to cmd.exe
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
You will have to P/Invoke SendInput() because Backspace is processed by the keyboard driver directly.
string msg = "Hello Cmd";
int i=0;
for (i=0; i < msg.Length ; i++)
SendMessage(cmdHwnd, WM_CHAR, (int)msg[i], 0);
the above method helps you input any character in a string also CAPS and Space are considered.
The only problem is what I am facing is if u send message previously and it is still processing then a string having same character twice like "channel" then string entered is chanel and not channel. I am currently finding a solution for this problem.
Murali can u share you code with me for KEYDOWN and KEYUP with KeyCode.
BR,
Rahul
use the ascii code: backspace --> OCT 0x10, char 'BS'
精彩评论