简体   繁体   English

如何使用sendmessage(C#)向cmd.exe发送退格键

[英]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. 我正在尝试向我从我的应用程序启动的cmd.exe发送击键。 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. 这样做,我能够发送所有键盘字符,但如果我尝试发送Backspace,它似乎没有生效。 The following is the code snippet to send message to cmd.exe: 以下是向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? 从C#应用程序发送到cmd.exe的stdin的最佳方法是什么?

thanks in advance 提前致谢

您必须P / Invoke SendInput(),因为Backspace由键盘驱动程序直接处理。

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. 上面的方法可以帮助您输入字符串中的任何字符,也可以考虑CAPS和Space。

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. 唯一的问题是我面临的问题是,如果您之前发送消息并且它仍处理然后处理具有相同字符的字符串两次,如“频道”,则输入的字符串是chanel而不是频道。 I am currently finding a solution for this problem. 我目前正在为这个问题找到解决方案。

Murali can u share you code with me for KEYDOWN and KEYUP with KeyCode. Murali可以和我分享KEYDOWN的代码和KeyCode的KEYUP代码。

BR, BR,

Rahul 拉胡尔

使用ascii代码:退格 - > OCT 0x10,char'BS'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM