First, insert three using statement as below
- using System.Drawing;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
ข้างล่างนี้เป็นคลาสสำหรับควบคุมเม้าส์เคอร์เซอร์
This is a class to control mouse cursor
- class MouseCursor
- {
- [DllImport("user32.dll")]
- private static extern bool SetCursorPos(int x, int y);
- public static void MoveCursor(int x, int y)
- {
- SetCursorPos(x, y);
- }
- [DllImport("user32.dll")]
- private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
- public enum MouseEventType : int
- {
- LeftDown = 0x02,
- LeftUp = 0x04,
- RightDown = 0x08,
- RightUp = 0x10
- }
- public static void MouseDown()
- {
- mouse_event((int)MouseEventType.LeftDown, Cursor.Position.X, Cursor.Position.Y, 0, 0);
- }
- public static void MouseUp()
- {
- mouse_event((int)MouseEventType.LeftUp, Cursor.Position.X, Cursor.Position.Y, 0, 0);
- }
- }