Advertisement
Apidcloud

Mouse Utilities

Apr 4th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. public static class MouseUtilities
  2.     {
  3.         // import the necessary API function so .NET can
  4.         // marshall parameters appropriately
  5.         [DllImport("user32.dll")]
  6.         static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
  7.  
  8.         // constants for the mouse_input() API function
  9.         private const int MOUSEEVENTF_MOVE = 0x0001;
  10.         private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
  11.  
  12.         // simulates movement of the mouse. parameters specify changes
  13.         // in relative position. positive values indicate movement
  14.         // right or down
  15.         public static void Move(int xDelta, int yDelta)
  16.         {
  17.             mouse_event(MOUSEEVENTF_MOVE, xDelta, yDelta, 0, 0);
  18.         }
  19.  
  20.         // simulates movement of the mouse. parameters specify an
  21.         // absolute location, with the top left corner being the
  22.         // origin
  23.         public static void MoveTo(int x, int y)
  24.         {
  25.             mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement