English 中文(简体)
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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签