티스토리 뷰
메모장이 실행되기를 기다렸다가, 메모장에 문장을 입력하는 샘플코드이다.
Thread를 이용한 것이다.
이것은 AutoIt, AutoHotKey 같은 Task Automation 프로그램 대용으로 활용할 수 있다.
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)
{
ThreadStart myThreadStart = new ThreadStart(DoWork);
Thread myThread = new Thread(myThreadStart);
myThread.Start();
myThread.Join();
}
static void DoWork()
{
bool done = false;
do
{
Process[] myProcesses = Process.GetProcesses();
foreach (Process item in myProcesses)
{
if (item.ProcessName == "notepad")
{
SetForegroundWindow(item.MainWindowHandle);
Thread.Sleep(1000);
SendKeys.SendWait("Hello World");
SendKeys.SendWait("{ENTER}");
done = true;
}
}
Thread.Sleep(500);
Application.DoEvents();
} while (!done);
}
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
Thread를 이용한 것이다.
이것은 AutoIt, AutoHotKey 같은 Task Automation 프로그램 대용으로 활용할 수 있다.
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)
{
ThreadStart myThreadStart = new ThreadStart(DoWork);
Thread myThread = new Thread(myThreadStart);
myThread.Start();
myThread.Join();
}
static void DoWork()
{
bool done = false;
do
{
Process[] myProcesses = Process.GetProcesses();
foreach (Process item in myProcesses)
{
if (item.ProcessName == "notepad")
{
SetForegroundWindow(item.MainWindowHandle);
Thread.Sleep(1000);
SendKeys.SendWait("Hello World");
SendKeys.SendWait("{ENTER}");
done = true;
}
}
Thread.Sleep(500);
Application.DoEvents();
} while (!done);
}
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
'Code > C#' 카테고리의 다른 글
.NET Compact Framework Project Sample (0) | 2008.08.13 |
---|---|
Cursor.Position, SetCursorPos, mouse_event 샘플코드 (0) | 2008.04.18 |
Process : 메모장에 키 입력하기 (0) | 2008.04.17 |
Process : Notepad 종료 샘플코드 (0) | 2008.04.17 |
Process 목록 출력 샘플코드 (0) | 2008.04.17 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- .net framework
- java
- Service pack
- windows
- WinAutomation
- DotNetMagic
- 스크린캡쳐
- Automation
- Regular Expressions
- autohotkey
- iTextSharp
- Phalanger
- jre
- 애드센스감추기
- Sample Code
- tagREADYSTATE
- 애드센스숨기기
- AdSense감추기
- iText
- Rollback Rx
- download.com
- registry
- AxWebBrowser
- Microsoft
- AdSense숨기기
- c#
- READYSTATE_COMPLETE
- 유틸리티
- ScreenHunter
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함