Guest User

Untitled

a guest
Sep 21st, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1.     class Mouse
  2.     {
  3.         [Flags]
  4.         public enum MouseEventFlags
  5.         {
  6.             LeftDown = 0x00000002,
  7.             LeftUp = 0x00000004,
  8.             MiddleDown = 0x00000020,
  9.             MiddleUp = 0x00000040,
  10.             Move = 0x00000001,
  11.             Absolute = 0x00008000,
  12.             RightDown = 0x00000008,
  13.             RightUp = 0x00000010
  14.         }
  15.  
  16.         [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
  17.         [return: MarshalAs(UnmanagedType.Bool)]
  18.         private static extern bool SetCursorPos(int X, int Y);
  19.  
  20.         [DllImport("user32.dll")]
  21.         [return: MarshalAs(UnmanagedType.Bool)]
  22.         private static extern bool GetCursorPos(out MousePoint lpMousePoint);
  23.  
  24.         [DllImport("user32.dll")]
  25.         private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
  26.  
  27.         [StructLayout(LayoutKind.Sequential)]
  28.         public struct MousePoint
  29.         {
  30.             public int X;
  31.             public int Y;
  32.  
  33.             public MousePoint(int x, int y)
  34.             {
  35.                 X = x;
  36.                 Y = y;
  37.             }
  38.         }
  39.  
  40.         public static void SetCursorPosition(int X, int Y)
  41.         {
  42.             SetCursorPos(X, Y);
  43.         }
  44.  
  45.         public static void SetCursorPosition(MousePoint point)
  46.         {
  47.             SetCursorPos(point.X, point.Y);
  48.         }
  49.  
  50.         public static MousePoint GetCursorPosition()
  51.         {
  52.             MousePoint currentMousePoint;
  53.             var gotPoint = GetCursorPos(out currentMousePoint);
  54.             if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); }
  55.             return currentMousePoint;
  56.         }
  57.  
  58.         public static void MouseEvent(MouseEventFlags value)
  59.         {
  60.             MousePoint position = GetCursorPosition();
  61.  
  62.             mouse_event
  63.                 ((int)value,
  64.                  position.X,
  65.                  position.Y,
  66.                  0,
  67.                  0)
  68.                 ;
  69.         }
  70.  
  71.         static void Main(string[] args)
  72.         {
  73.             SetCursorPosition(40, 40);
  74.             MouseEvent(MouseEventFlags.LeftUp | MouseEventFlags.LeftDown);
  75.         }
  76.  
  77.  
  78.  
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment