1

If I wanted to control the mouse cursor, including clicking etc, what API would I need to use for this? For example, i'm developing an application for the PC using the Kinect, and I wish to control the mouse cursor with this, as opposed to creating my own in-app cursor. What would I need to 'tap into' to achieve this?

Thanks.

Darren Young
  • 10,972
  • 36
  • 91
  • 150
  • possible duplicate of [How to simulate Mouse Click in C#?](http://stackoverflow.com/questions/2416748/how-to-simulate-mouse-click-in-c) – RvdK Nov 02 '11 at 10:42
  • See http://stackoverflow.com/questions/1503238/whats-the-difference-between-using-cursor-position-setcursorpos-sendinput. – Anton Tykhyy Nov 02 '11 at 10:43

1 Answers1

2

See answer from Marcos Placona in: How to simulate Mouse Click in C#?

Now you only need to add the mouse move events. More info here: http://pinvoke.net/default.aspx/user32.mouse_event

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class Form1 : Form
{
   [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
   public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

   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 Form1()
   {
   }

   public void DoMouseClick()
   {
      //Call the imported function with the cursor's current position
      int X = Cursor.Position.X;
      int Y = Cursor.Position.Y;
      mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
   }

   //...other code needed for the application
}
Community
  • 1
  • 1
RvdK
  • 19,580
  • 4
  • 64
  • 107