C#

[C#]마우스 이벤트(mouse_event) 예제

선영아 사랑해 2018. 5. 21. 10:18


using System.Runtime.InteropServices;


[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);


const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;


private void button1_Click(object sender, EventArgs e)

{

       Cursor.Position = new Point(this.Location.X + 20, this.Location.Y + 10);


       mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
       mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}


//커서의 현재 위치에서 마우스 좌 클릭 이벤트 발생하는 WIN API 예제 소스 입니다.