0

How would I go about sending a string of characters as a keystroke in C#? An example would be opening notepad or a browser and having the string populate in the address bar or notepad file. I want to be able to just manually open an application and see my string appear. I've already tried passing it by process and using handlers to open the application, then having the string populate the file. A snippet of this has been attached below. I've also looked into the input simulator at codeplex.com. Is it possible to do this without using the input simulator?

namespace StringOutput
{
    class StringSend : Form
    {
        [DllImport("USER32.dll")]
        static extern bool ShowWindow(IntPtr point, int nCmdShow);

        public static void Main()
        {

            Process notepad = new Process();
            notepad.StartInfo.FileName = @"C:\Windows\Notepad.exe";
            notepad.Start();
            notepad.WaitForInputIdle();

            IntPtr p = notepad.MainWindowHandle;
            ShowWindow(p, 1);

            SendKeys.SendWait("Testing");
    }
       }
}
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
fuser
  • 3
  • 2
  • Dup? http://stackoverflow.com/questions/3047375/simulating-key-press-c-sharp – Arsen Mkrtchyan Apr 25 '16 at 15:49
  • The solution suggested calling the process, then sending the input, but I included my example of how I already did that, and was questioning if there was an alternative way? – fuser Apr 25 '16 at 15:53
  • In your case you create Process, in solution, he get process list from the processes list... if you call SendKey on your process, it should work – Arsen Mkrtchyan Apr 25 '16 at 15:54

0 Answers0