Kinect v2 Mouse Control w/ Source Code

A mouse control application for Kinect v2, including a couple of options for various uses.

Kinect v2 Mouse Control Form Screenshot


I’m so glad that I’ve just become a Microsoft Kinect MVP since this July, so I think I need to do something more.

One request asked most since the original Kinect came out is, “can I use my hand to control the mouse cursor?” There you can find a few applications for doing this with original Kinect on the web.

These days, some people still asked me for this kind of application for Kinect v2. Then I strangely found there’s no such downloadable applications on the web. I gotta release a Kinect v2 version app. And here’s it, with source code!


Options:

  • Mouse Sensitivity
  • Pause-To-Click Time Required
  • The time you hold your hand for as a click

  • Pause Movement Thresold
  • How large the circle range you hold your hand inside for a little while would be a click

  • Cursor Smoothing
  • The large it is, the smoother the cursor would move, more slowly as well.

  • Grip Gesture
    Grip to drag/click
  • Pause To Click
    Hold your hand and don’t move for a little while to click.
  • No clicks, move cursor only

Github: KinectV2MouseControl
EXE files: [download id=”24″]


About TangoChen

Interest driven for tech & music.
This entry was posted in Kinect, Tech. Bookmark the permalink.

35 Responses to Kinect v2 Mouse Control w/ Source Code

  1. Alex says:

    Hi,
    When I run this the light on the Kinect lights but I don’t seem to be able to control the PC cursor. Help?

    • TangoChen says:

      Hi, I just tested again with the app and it worked. It should also work for you.
      Here’re 2 reasons I guess it may cause the problem:

      • Your Kinect is opened but cannot find(detect) your body. Please make sure your body is detectable to the Kinect. Maybe you need to step further and move your hands and feet a little bit so that the Kinect can find your body.
        You can also run Body Basics-WPF the sample application in SDK Browser at the same time. If it’s shows the skeleton view, your body is detected.
      • The Mouse Sensitivity in the app is set too low. Please set it higher or click Default to set it to default value.
  2. kamithekira says:

    Hi can you add distance control cause i must be near of the kinect for the cursor to work well, also add infrared detection to use it in dark room , thank you for your great work ^^

  3. kamithekira says:

    hi, are you planing to make update yes or no ?

  4. Henry says:

    Hi ! Thanks for sharing this great piece of software, its the best one I’ve came across for the Kinect V2, the only thing is the mouse seems to move a lot when you try to click on anything using the grab gesture.
    Would it be possible to set it so you move the mouse with your right hand and then click with the left ?
    Thanks for your time.
    Henry P.

  5. Giuseppe says:

    Thank you very much!
    It’s amazing!
    Is there some way to limit range of hand recognition and improve user switching(2 or 3 persons in front of the camera)?

  6. Amit Sharma says:

    HI,
    I have downloaded you code. It working with Drag n Drop of items, Cursor Movement.
    But its not working with the OSK (On screen keyboard).

    Can you please let me know that why its not working with On Screen Keyboard.

    Reply Soon.

  7. hasaky says:

    hello my name is hasaky.
    I want to learn how to coding with kinect v2.
    can u suggest some website or material to let me learn kinect v2?
    plz
    :)

  8. Seethal Joseph says:

    hai how to control double click and Drag ?????
    I download this and working and i need to double click and drag n drop can pls tell me how to ?

  9. kick says:

    hi!! I want to create a program where the pointer follows the hand. Can I tell if I am using processing3 and what function is following it?
    no using kinect v2.

    • TangoChen says:

      Hi kick, I don’t have experiences with processing on that and I don’t know what functions it has. But I’d share a basic idea, to achieve this, usually you need to find functions to get your body joints positions, which includes your hand positions, and shoulder positions used as what I did for increasing stabilities. And map those positions into expected onscreen pointer positions. (They’re in different dimensions, x-axis of your hand position moving 5 units can possibly be expected to have 2000 pixels movement on screen! Then you just multiply the x value, and maybe add a offset value if needs, and so on.. Based on how you want it to move.)

  10. alan torres says:

    I have a question, how do you use it? do I need a special program? or just connect the kineckt to the computer and run the exe ? thanks!

  11. steven chang says:

    Sorry! TangoChen ~ I ask the question, I downloaded Kinect v2 MouseControl.exe, but MouseControl.exe no action! ? I use win7 x64 version, kinect already installed driver. Also, install Visual Studioc 2017. Thank you!

    • TangoChen says:

      Hi Steven, would it work to run other Kinect samples? (Basic demos in SDK browser)
      Just to make sure your Kinect installation and setup is fine for any Kinect apps.

      • steven chang says:

        TangoChen ~ Right! I downloaded [KinectV2MouseControl-master] and I saw it using [C # Code]. Whether [C # code] to compile, you can do it! ? Thank you (p.s: do you have email?)

  12. Pingback: New Kinect Interaction – Angel Wu – Week 02 PPJ – Coalescence

  13. Junior says:

    Hi,

    are you still working on this project or will this be the last version of the app? Just asking because i couldnt find any useful Alternative and Microsoft more or less dumped the kinect and i still have some problems with the usage e.g. Compare the comment of Henry. So you are my last hope for this. In case you will not further work on this i have to drop my use for it aswell or is anybody else here who is still working on this?

    • TangoChen says:

      Hi buddy, the jittering appears when gripping also causes tracked position moves, which can’t be simply gotten rid of using only the simple body tracking outcome. (May be able to find a workaround somehow. I’m not trying yet. Or may never do.)

      As for two-hand controlling(one hand for moving another for clicking) as Henry mentioned. I personally don’t think this is an intuitive, or good-looking way of controlling the cursor. But it does solve the jittering to a certain degree comparing to current function. And if people are okay with this gesture for their scenarios, it’s quite fine.

      Am I still working on it or will it be the last version?: I would try to do my stuff mostly when I want. So I rarely determine something is forever done or yet to be continued. But would be a matter of time and arrangement.
      I’m going to add the two-hand controlling option. While I’m procrastinating with other things, too. May take around a week or two to have this update..

  14. Junior says:

    Hi,

    nice to hear, that there is still afford for improvements. Anyway, i did not want to trouble you with this. I agree that a two hand solution is not very intuitive, but for the moment it is probably the easiest way. Maybe some other readers take on off this project any time. It is pretty sad ms dropped the kinect instead of take it as a basis for future development. Nevertheless, i just read ms will introduce a wider range of controlling options for handycaped people with the next os update. We will see, maybe the kinect will have a second awakening.

    • TangoChen says:

      I agree. I would had been looking forward to a Kinect 3, 4 and more if they didn’t discontinue it. As Kinect is still one of the most practically usable and useful tech devices compared to many gimmicks nowadays. And it still can have a lot of potentials with difference improvements.
      HoloLens is partially another form of Kinect but in a more specific scenario. Any enhanced forms of Kinect, or something that may lead the potentials would be nice. :)

    • TangoChen says:

      Hi,
      FYI, the KinectV2MouseControl was just updated with two-hand controls.
      Link: https://github.com/TangoChen/KinectV2MouseControl

      • Junior says:

        Hi,

        just tested the last version and its great. Works very fluently and intuitiv, i have to commit it firts looks a bit strange but because of the prompt recognicen you only have to lift the hand just very short and with a bit of usage you get on it very fast. Thank you very much therefore. It is a great improvement. Now when you support two hand modus would it be difficult to combine two hand with two gestures. Eg. Move and lift for clicking and grip or press for doubleclick. So one hand for moving is the fixed command and then you can combine the command with a second hand alternatively either lift for click or grip/ press for doubleclick?

        By using the kinect a bit more intensively there still arise more and more points where ms had to improve its architecture for a future usage. There is e.g one point i have not think about before that could be a problem. I use the kinect on 32 inch touchscreen as a kind of infowall, the problem now is that because of the touchscreen i have no native mouse controll and because of that no constant cursor icon. When i now want to controll the the os with the kinect i first have to plug in a mouse to see where to move. This is e.g. an example for how many scenarious ms has to think of by improving the usage of the kinect. I still hope they will recognice one day what kind of future control option they have on the kinect.

        • TangoChen says:

          Hi,

          As to combining gestures, it’s doable. But currently I’m not planning to have some major updates.

          You’re right that people may need a bit of using on lift-clicking before getting on it. 
There were some intends to make the gesture as “lifting the hand just very short”. At first I was making the lifting to a higher distance over the head, which is what most people would potentially do to “lift their hand”. But in the meanwhile “lift clicking” is the only major gesture besides moving the cursor. It could be frequently used.
          So I think there’re two advantages to make the triggering height lower, just around the neck.
          1. People can put their hand lower or just put it down before doing a click, it feels less strength consuming, especially when clicking is frequently needed.
          2. The approximate triggering height is clearer for users after experiencing. Though the height is not same for everyone. It could be around the height of your neck. Or around the height of your mouth. But then you kind of know where it is. If it’s above your head, you may know or feel less on the height, and may have to think of putting up your hand to the top. It works but also a bigger strength consumption.
          These may be very little things though. I like to have some sort of long term convenience. There are also advantages to make it higher above the head. e.g. For short term usages by constant new people. No worry, there’s a HandLiftYForPress property for adjusting the height in KinectCursor.cs for developers.

  15. Wim Mussche says:

    Hi,
    We are using your application for testing purposes. Our application is very straight forward. When hovering a button in windows 10, it has to accept a “click” event. All goes well with one person in the detection area. We are looking for a solution where only one person (eg the first person that is detected) can move the cursor without other people in the detection area influence the working of the app. An application is not fool proof when it is not accurate enough. Now the cursor becomes very unstable and the application crashes (the connection with the Kinect interrupts). We are wondering if you can help us with this? I tried to launch a project on freelancer.com, but all programmers want to use Untiy, but we are not asking for a game, but normal windows click commands.

  16. Sandro says:

    Hi, I tried to compile your source but i got this error “Error 1 Invalid token ‘=’ in class, struct, or interface member declaration”

    please advice how to fix this error.

    • Sandro says:

      it points to line 86 column 48…
      public double HoverRange { get; set; } = 20;

      • TangoChen says:

        Hi Sandro, it seems that you are using an old version of Visual Studio(with old C# version). As C# before 6.0 doesn’t support for auto-property initializer, which let you directly initialize the property with an assignment operator(= 20 in this case).

        To fix this for you, either try using a newer version of Visual Studio, e.g. VS 2015, 2017.
        Or with a little adjustment on the code. You can change line 86 to:
        private double _hoverRange = 20;
        public double HoverRange {
        get
        {
        return _hoverRange;
        }
        set
        {
        _hoverRange = value;
        }
        }

        or

        // Remove "= 20;" in the end.
        public double HoverRange { get; set; }

        // and insert this at line 119 for KinectCursor constructor:
        HoverRange = 20;

        • Sandro says:

          Thank you TangoChen. Now I can build and execute without error.

          but, how can I use this app? when I try to run, the mouse control window will appear but I can’t control the mouse

          • TangoChen says:

            Hi Sandro, is the Control Mode on the app set to Disabled? If yes then you need to select other mode options to activate the control.

  17. Sandro says:

    any option in the control mode doesn’t work. what I know is that, it is not connecting my Kinect because the red light in my kinect is not turning on.

    the other kinect programs I downloaded and run is working but the interface is not good.

    • TangoChen says:

      Hi, is there a Microsoft.Kinect.dll is under the app folder? If not, try copying one from Kinect SDK folder to there. You can also use executables/KinectV2MouseControl_EXE.zip from the source.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.