title: Mouse move automation in windows service
body: <p>I have created a Windows Service,
  In the On start method, i am invoking a Listener for an input device</p>
  
  <pre><code>public class LeapMouseServiceService : ServiceBase
  {
      private Controller cnt;
      private LeapListener ls;
      public LeapMouseServiceService()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {            
          this.cnt.AddListener(ls);
      }
  </code></pre>
  
  <p>MouseOpera has mouse_event from USer32.dll</p>
  
  <pre><code>    class MouseOpera
  {
      [System.Runtime.InteropServices.DllImport("user32.dll")]
      private static extern bool SetCursorPos(int x, int y);
      [System.Runtime.InteropServices.DllImport("user32.dll")]
      private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
  
      private const int MOUSEEVENTF_MOVE = 0x01;
      private const int MOUSEEVENTF_LEFTDOWN = 0x02;
      private const int MOUSEEVENTF_LEFTUP = 0x04;
      private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
      private const int MOUSEEVENTF_RIGHTUP = 0x10;
  
      public static void DeltaMove(int x, int y)
      {
          mouse_event(MOUSEEVENTF_MOVE, x, y, 0, 0);
      }
  </code></pre>
  
  <p>LeapListener Class has Onframe method</p>
  
  <pre><code>class LeapListener : Listener
  {
      private Object thisLock = new Object();
      System.IO.StreamWriter sw = new System.IO.StreamWriter(@"K:\logs\log.txt",true);
      private void SafeWriteLine(String line)
      {
          lock (thisLock)
          {                
              sw.WriteLine(line);
          }
      }
      public override void OnInit(Controller controller)
      {
          SafeWriteLine(DateTime.Now.ToShortDateString());
          SafeWriteLine("Initialized");
      }
  
      public override void OnConnect(Controller controller)
      {
          SafeWriteLine("Connected");
      }
  
      public override void OnDisconnect(Controller controller)
      {
          //Note: not dispatched when running in a debugger.
          SafeWriteLine("Disconnected");
      }
  
      public override void OnExit(Controller controller)
      {
          SafeWriteLine("Exited");
      }
  
      public override void OnFrame(Controller controller)
      {
          // Get the most recent frame and report some basic information
          Frame frame = controller.Frame();
          MouseOpera.DeltaMove((int)(hand.Direction.Yaw*10),-(int)(hand.Direction.Pitch*10));
  </code></pre>
  
  <p>The log.txt is perfectly capturing all Leap activities when Service is running. But, the mouse movement is not happening. How to make the mouse move automatically from windows service using C# code? </p>