2012-03-24 3 views
0

.NET 응용 프로그램 캡처는 웹캠에서 특정 유형의 객체의 동작을 감지합니다. 개체의 동작을 번역하여 내 양식 내에서 마우스의 움직임을 제어 할 수 있습니다. 그러나 어떤 형태의 가상 마우스처럼 내 양식 외부에서 마우스 움직임을 제어하려고합니다..NET을 사용하여 웹캠에서 마우스 포인터를 제어하는 ​​모션 감지

이것을 달성하는 가장 좋은 방법은 무엇입니까?

답변

0

가 클릭을 수행하고 코드를 통해 형태로 외부에 커서를 이동하려면 :

[DllImport("user32.dll")] 
static extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo); 
#region mouseConstants 
const int MOUSE_MOVE = 0x00000001; 
const int MOUSE_LEFTDOWN = 0x00000002; 
const int MOUSE_LEFTUP = 0x00000004; 
const int MOUSE_RIGHTDOWN = 0x00000008; 
const int MOUSE_RIGHTUP = 0x00000010; 
const int MOUSE_MIDDLEDOWN = 0x00000020; 
const int MOUSE_MIDDLEUP = 0x00000040; 
const int MOUSE_WHEEL = 0x00000800; 
const int MOUSE_ABSOLUTE = 0x00008000; 
#endregion 

private void performClick(int posX, int posY) 
{ 
    Cursor.Position = new Point(posX, posY); // to move the cursor at desired position 
    mouse_event(MOUSE_LEFTDOWN, 0, 0, 0, 0); // to perform left mouse down 
    mouse_event(MOUSE_LEFTUP, 0, 0, 0, 0); // to perform left mouse up 
} 
2

당신은 승리 API 호출을 통해이를 달성 시도해 볼 수도 있습니다 :이 응용 프로그램 외부에서 일하는 것이

[DllImport("user32.dll")] 
static extern bool SetCursorPos(int X, int Y); 

[DllImport("user32.dll")] 
public static extern bool GetCursorPos(out Point pt); 

Point current; 
GetCursorPos(out current); 
SetCursorPos(current.X + 10, current.Y + 10); 

. C#에서

+0

감사합니다. 나는 user32.dll을 사용하여 마우스 이벤트를 제어하는 ​​것도 가능하다고 생각했습니다. – Naveen

1

:

//using System.Windows.Forms; 
//using System.Drawing; 
Cursor.Position = new Point(x, y); 

또는 당신은 오히려 위치보다, 마우스를 이동하려면 :

//using System.Windows.Forms; 
//using System.Drawing; 
Cursor.Position = Cursor.Position + new Size(deltaX, deltaY); 
+0

감사합니다 .... 코드를 통해 양식 외부에서 클릭 또는 더블 클릭을 수행 할 수 있습니까 ??? – Naveen

+0

@Naveeen : 예,하지만 훨씬 더 복잡합니다. 좋은 예가 있습니다 : http://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library –

관련 문제