티스토리 뷰
Cursor.Position, SetCursorPos, mouse_event 를 이용해서 마우스를 컨트롤하는 샘플코드이다.
원하는 위치로 이동할 수도 있고, 마우스 클릭도 조절할 수 있다.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace MouseSample
{
class Program
{
static void Main(string[] args)
{
Point myPoint = new Point();
myPoint.X = 10;
myPoint.Y = 10;
Cursor.Position = myPoint;
Thread.Sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, (UIntPtr)0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, (UIntPtr)0);
Thread.Sleep(500);
SetCursorPos(25, 1030);
Thread.Sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, (UIntPtr)0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, (UIntPtr)0);
Thread.Sleep(500);
myPoint.X = Cursor.Position.X + 200;
myPoint.Y = Cursor.Position.Y - 200;
Cursor.Position = myPoint;
}
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern void mouse_event(uint dwFlags,
long dx, long dy, uint dwData, UIntPtr dwExtraInfo);
private const uint MOUSEEVENTF_MOVE = 0x0001;
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
private const uint MOUSEEVENTF_LEFTUP = 0x0004;
private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const uint MOUSEEVENTF_RIGHTUP = 0x0010;
private const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
private const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
private const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
}
}
원하는 위치로 이동할 수도 있고, 마우스 클릭도 조절할 수 있다.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace MouseSample
{
class Program
{
static void Main(string[] args)
{
Point myPoint = new Point();
myPoint.X = 10;
myPoint.Y = 10;
Cursor.Position = myPoint;
Thread.Sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, (UIntPtr)0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, (UIntPtr)0);
Thread.Sleep(500);
SetCursorPos(25, 1030);
Thread.Sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, (UIntPtr)0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, (UIntPtr)0);
Thread.Sleep(500);
myPoint.X = Cursor.Position.X + 200;
myPoint.Y = Cursor.Position.Y - 200;
Cursor.Position = myPoint;
}
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern void mouse_event(uint dwFlags,
long dx, long dy, uint dwData, UIntPtr dwExtraInfo);
private const uint MOUSEEVENTF_MOVE = 0x0001;
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
private const uint MOUSEEVENTF_LEFTUP = 0x0004;
private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const uint MOUSEEVENTF_RIGHTUP = 0x0010;
private const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
private const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
private const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
}
}
'Code > C#' 카테고리의 다른 글
[C#] ADO.NET XML and DataGridView Binding Sample Project (0) | 2008.12.20 |
---|---|
.NET Compact Framework Project Sample (0) | 2008.08.13 |
Process : Thread를 이용한 메모장에 키 입력하기 (0) | 2008.04.18 |
Process : 메모장에 키 입력하기 (0) | 2008.04.17 |
Process : Notepad 종료 샘플코드 (0) | 2008.04.17 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- c#
- download.com
- Microsoft
- .net framework
- READYSTATE_COMPLETE
- ScreenHunter
- windows
- iTextSharp
- autohotkey
- AdSense감추기
- jre
- Rollback Rx
- 애드센스감추기
- Regular Expressions
- 애드센스숨기기
- registry
- AdSense숨기기
- 유틸리티
- 스크린캡쳐
- DotNetMagic
- iText
- Phalanger
- Automation
- AxWebBrowser
- WinAutomation
- java
- tagREADYSTATE
- Service pack
- Sample Code
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함