0

I find it very interesting when I can control a console window with my C#/C++ program.

According to this post: Programmatically Paste Clipboard Text to a CMD Window (C# or C++), we can execute paste command for a console with this code

 // hwnd is the window handle of a console window
 SendMessage(hwnd, WM_COMMAND, 0xfff1, 0);

So 0xfff1 is the command (wParam) for Paste. But I see that there are several useful commands:

  1. Copy

  2. Select All

  3. Paste ---> 0xfff1

  4. Execute command (When you press Enter to execute a cmd command)

  5. Clear current input (when you press Esc)

  6. Ctrl + C command (you know what that is, not copy btw)

If I have the execute command, then I can combine paste & execute to programmatically execute a command in a console from my software. Or if I know "Select All" & "Copy", I can programmatically copy the content of the console. console So does anyone know the programmatic command code (wParam) of the command above? Especially the execute command.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
123iamking
  • 2,387
  • 4
  • 36
  • 56
  • 2
    Have you tried to paste the command with an ending CRLF? – MC ND Apr 02 '18 at 18:48
  • 1
    For what it's worth, the menu command IDs can easily be read from the console host DLL multi-language user interface resource file (e.g. "en-us\ConhostV2.dll.mui"). In order of ID, the menu items are copy (0xfff0), paste (0xfff1), mark (0xfff2), scroll (0xfff3), find (0xfff4), and select all (0xfff5). – Eryk Sun Apr 02 '18 at 22:59
  • @MCND - Thank you, so paste the `Environment.NewLine //C#` equal run command, I should have known it :D @eryksun - Thank you, you're right, I've tried: select all & copy, it works. – 123iamking Apr 03 '18 at 02:15

0 Answers0