Click here to Skip to main content
13,593,655 members
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 23 Apr 2012
Licenced CPOL

The Kinect Mouse Controller C#

, 2 Nov 2012
Rate this:
Please Sign up or sign in to vote.
In this tip, I will describe how to implement a cursor controller in your project that use the Kinect to control the mouse of your PC.

The zip file provided with this article contains a DLL file KinectMouseController.DLL that could be used in all kinds of C# projects to control the cursor of Windows OS system from a Kinect device.

This schema explains how the provided DLL could be useful to send position (x,y) from the Kinect device to the Windows cursor:


Controlling the cursor using the Kinect is a common question that I have noticed in many web sites, This feature could help a lot of people to make something more interactive, Designer, Architect, exploring maps, exploring 3D building ,... etc.

So in this quick description, I will explain how to add this feature to your project and also provide an application that could help people who aren't familiar with User32.dll and Kinect SDK.


Having an experience with Kinect SDK isn't a must to benefit from this DLL,you should have some basics in coding a Kinect application to implement cursor controller in your Kinect project and use my code.

You should have a Kinect device, install the Kinect SDK and have hardware requirements to benefit from Kinect device in your computer.

Learn my first article about the Kinect for more details, and take a look at this.

What is User32 ?

User32 is one of the DLLs cached on system32 of Windows OS.

It's a Microsoft DLL that provides a lower-level control of Windows, menu, mouse, keyboard,... etc, it's based on many native methods; MOUSE_EVENT etc. that allows a control of a Windows user interface.

Using the Code

To use the DLL KinectMouseController in your project, you should first add a reference to this DLL in your project.

So after creating a project that will use the Kinect SDK, right click the reference folder of your project:

Choose the Browse tab, and select the KinectMouseController.DLL:

In your .cs file where you need to use the mouse controller, add a using KinectMouseController:

Now, you can use the following method:

SendMouseInput(int CursorX, int CursorY,int ScreenWidth, int ScreenHeight, bool isClicked)

In this method, we give the mouse position, the screen dimension and a boolean that represents a mouse click, true if down and false if up.

KinectMouseController.KinectMouseMethods.SendMouseInput(cursorX, cursorY, 
 (int)SystemInformation.PrimaryMonitorSize.Height, true); 

This code could be used in nui_SkeletonFrameReady() of Kinect SDK, in this code I'll use it to control the mouse using my right hand ,e.g :

void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            //get the first tracked skeleton
            SkeletonData skeleton = (from s in allSkeletons.Skeletons 
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();
            //Test if skelton exist and tracked
            if (skeleton != null && skeleton.TrackingState == SkeletonTrackingState.Tracked)
                SwG.Add(skeleton.Joints[JointID.HandRight].Position, nui.SkeletonEngine);

                // scale those Joints to the primary screen width and height 
                Joint scaledRight = skeleton.Joints[JointID.HandRight].ScaleTo((
                    SkeletonMaxX, SkeletonMaxY);

                int cursorX = (int)scaledRight.Position.X;
                int cursorY = (int)scaledRight.Position.Y;
	(cursorX, cursorY, (int)SystemInformation.PrimaryMonitorSize.Width, 
	(int)SystemInformation.PrimaryMonitorSize.Height, false); 

In the nui_SkeletonFrameReady(), we detect the first Skelton, after that we get the right hand portion of this skelton cursorX and cursorY, those coordinates are passed to the SendMouseInput() method of the KinectMouseController to take control of the mouse using the right hand of the first detected Skelton.

Points of Interest

I also wrote a related article:


This code is tested with Windows 7, Kinect SDK beta 1 and Visual Studio 2010.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Saad Mousliki
Technical Writer SaadMos
Morocco Morocco
currently an IT Manager (ITSM), with background in Web, Mobile and Could
specialized in Web and software: JavaScript; Wakanda; ASP.NET, C #, WPF, JAVA, C... (SQL Server, jQuery, AJAX, ...)
I am also interested to mobile: Kinect, iOS, hybrid mobile app, and Android
To contact me :

You may also be interested in...


Comments and Discussions

Questionflash with kinect Pin
Member 1251581010-May-16 19:04
memberMember 1251581010-May-16 19:04 
Questiongood day! Pin
Ralph Jason Austin Fonte15-Sep-14 22:20
memberRalph Jason Austin Fonte15-Sep-14 22:20 
AnswerRe: good day! Pin
Saad Mousliki15-Sep-14 22:29
memberSaad Mousliki15-Sep-14 22:29 
GeneralRe: good day! Pin
Ralph Jason Austin Fonte16-Sep-14 15:33
memberRalph Jason Austin Fonte16-Sep-14 15:33 
QuestionCode Pin
Minh Map Vu12-Feb-14 17:17
memberMinh Map Vu12-Feb-14 17:17 
AnswerRe: Code Pin
Saad Mousliki12-Feb-14 17:56
memberSaad Mousliki12-Feb-14 17:56 
QuestionThe Kinect mouse controller C# Pin
miguel061222-Nov-12 19:37
membermiguel061222-Nov-12 19:37 
AnswerRe: The Kinect mouse controller C# Pin
saadmos22-Nov-12 22:36
membersaadmos22-Nov-12 22:36 
Generalhihi Pin
hoangquybao4-Sep-12 22:02
memberhoangquybao4-Sep-12 22:02 
GeneralRe: hihi Pin
saadmos4-Sep-12 23:54
membersaadmos4-Sep-12 23:54 
GeneralRe: hihi Pin
hoangquybao5-Sep-12 19:20
memberhoangquybao5-Sep-12 19:20 
GeneralRe: hihi Pin
saadmos14-Sep-12 0:32
membersaadmos14-Sep-12 0:32 
GeneralRe: hihi Pin
hoangquybao16-Sep-12 13:55
memberhoangquybao16-Sep-12 13:55 
QuestionCould you help me please Pin
Chinnawat Heranya11-Aug-12 6:14
memberChinnawat Heranya11-Aug-12 6:14 
AnswerRe: Could you help me please Pin
saadmos14-Aug-12 3:07
membersaadmos14-Aug-12 3:07 
QuestionControl Windows 7 with Kinect SDK with Source Code Pin
alhazmi112-May-12 17:53
memberalhazmi112-May-12 17:53 
AnswerRe: Control Windows 7 with Kinect SDK with Source Code Pin
saadmos2-May-12 22:05
membersaadmos2-May-12 22:05 
GeneralRe: Control Windows 7 with Kinect SDK with Source Code Pin
alhazmi112-May-12 22:33
memberalhazmi112-May-12 22:33 
Questionthe kinect Pin
jimbobwillarby2-May-12 16:02
memberjimbobwillarby2-May-12 16:02 
QuestionThanks I see Pin
Member 888696029-Apr-12 4:21
memberMember 888696029-Apr-12 4:21 
AnswerRe: Thanks I see Pin
saadmos29-Apr-12 5:31
membersaadmos29-Apr-12 5:31 
GeneralRe: Thanks I see Pin
Member 888696029-Apr-12 15:20
memberMember 888696029-Apr-12 15:20 
GeneralRe: Thanks I see Pin
saadmos30-Apr-12 0:56
membersaadmos30-Apr-12 0:56 
Questionimages Pin
saadmos25-Apr-12 6:33
membersaadmos25-Apr-12 6:33 
QuestionKinect SDK Beta 1 or RTW v1? Pin
gduncan41123-Apr-12 6:21
membergduncan41123-Apr-12 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180618.1 | Last Updated 2 Nov 2012
Article Copyright 2012 by Saad Mousliki
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid