How to send backspace using sendmessage (C #) in cmd.exe

I am trying to send keystrokes to cmd.exe that I run from my application. With this I can send all the keyboard characters, but if I try to send Backspace, this does not seem to take effect. The following is a snippet of code for sending cmd.exe messages:

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

Any idea why this won't work? What is the best way to send stdin from cmd.exe from a C # application?

early

+3
source share
3 answers

You will need P / Invoke SendInput () , because Backspace is handled directly using the keyboard driver.

+1
source

string msg = "Hello Cmd";

int i=0; for (i=0; i < msg.Length ; i++)

SendMessage(cmdHwnd, WM_CHAR, (int)msg[i], 0);

, CAPS Space.

, , - , , , , , "", chanel, channel. .

Murali KEYDOWN KEYUP KeyCode.

,

+1

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

0
source

Source: https://habr.com/ru/post/1722791/


All Articles