Code/C#

Process : 메모장에 키 입력하기

Hide Code 2008. 4. 17. 23:50
메모장에 Hello World 문장을 입력하는 샘플코드이다.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace ProcessTest
{
   class Program
   {
       static void Main(string[] args)
       {
           Process[] myProcesses = Process.GetProcessesByName("notepad");

           foreach (Process item in myProcesses)
           {
               SetForegroundWindow(item.MainWindowHandle);
               Thread.Sleep(1000);
               SendKeys.SendWait("Hello World");
           }
       }

       [DllImport("user32.dll")]
       public static extern bool SetForegroundWindow(IntPtr hWnd);
   }
}