Sending Secondary Input to Command line After SendCommand. [.NET, C#]

Discussion in 'AutoCAD' started by Robert Clarkson, Dec 19, 2003.

  1. If anyone is interested in being able to send secondary input like
    "END<enter-key>", "CEN<enter-key>", or just simple Characters like "@" to
    the Command line, while the Command line is Active or Non-Quiescent, I have
    a solution.

    1) Open a class within your namespace called win32.cs

    2) Inside the Class
    using System;
    using System.Runtime.InteropServices;

    namespace WHATEVER
    {
    public class win32

    {
    [DllImport("User32.dll")]
    public static extern Int32 SetForegroundWindow(int hWnd);
    [DllImport("User32.dll")]
    public static extern void keybd_event(byte bVk, byte bScan, uint
    dwFlags, uint dwExtraInfo);
    }
    }

    3) How To Use within another class:

    public void Send_Chars (string s)
    {
    try
    {
    char[] strA = s.ToCharArray(); // Splits String into an Array
    win32.SetForegroundWindow(_application.HWND); // Needed to
    bring AutoCAD to the Foreground
    for (int i=0; i<strA.Length;i++)
    {
    win32.keybd_event((byte)strA,0,0,0); // KeyDown
    win32.keybd_event((byte)strA,0,2,0); // KeyUp
    Event
    }
    win32.keybd_event((byte)System.Windows.Forms.Keys.Enter,0,0,0);
    //Sends an ENTER keystrok
    }
    catch{}
    }
     
    Robert Clarkson, Dec 19, 2003
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.