Iris Classon
- CATALOG -
Iris Classon - In Love with Code

Developing for Leap Motion in C# Tutorial (video, slides and code)

Developing for leap Motion in C# Tutorial (video, slides and code)

I did a presentation on Leap Motion at the virtual conference DotnetConflast week, and I’ve spent the weekend cleaning up the code a little bit an putting together a simple video tutorial as it seems quite a few were interested and wanted some help to get started, and a step by step guide on how to develop for Leap Motion.

As soon as I find some time I will put together a detailed article on the Leap Motion- but I reckon you will get very far,- i not further with the video tutorial, the code, the conference session and the slides.

Here is everything you need - apart from the SDK and the device- to get started developing for Leap Motion in C#!

The slides

Developing for Leap Motion from Iris Classon

Slides on Leap Motion development can be found on my Slideshare account

Video tutorial with quick demo

I walk you through the what is it, how does it work (not as detailed as in the conference session), and then the code - step by step. The code is a WPF application using MVVM designpattern (not to 100%) and is a modified version of the application I made for the conference session. The Leap Motion application in C# and XAML can be found in my GitHhub repo Leap Motion (link provided below).

Developing for Leap Motion in C# Part 1
Developing for Leap Motion in C# Part 2

The conference session:

I demonstrate the Leap with several applications, get more into details of how it works, and I show both the code for three different console applications (that actually do the same thing LOL), and a WPF application.

The conference session on Leap Motion can be watched here. Slides used are the same as above, and can be found on Slideshare.

The code

The code for the application used for the tutorial can be found here, DLL’s for Leap Motion are not included as I’m not allowed to share those. Sign up, download the SDK and add the DLL’s as described in the tutorial or the slides.

Big thank you to Jeff Fritzfor taking the time to discuss code with me, where would we be without great colleagues and friends :) Also a big thanks to Carey, Scottand Michael:) - you know you rock ;)

Comments

Leave a comment (via email)
Sandeep
6/12/2013 12:35:48 AM
Thanks for the excellent tutorials Iris, i have a question "when the MainWindow is not in focus, leap doesnt try to read the fingers, how can we change that to read always? " 
Iris Classon
6/14/2013 5:51:22 AM
Reply to: Sandeep
Do you mean that you want a program that runs in the background as a service? 
Paul
6/14/2013 6:52:54 AM
Reply to: Iris Classon
I think that Sandeep wants to say : if the mainwindow is open but an other windows of an other program has the focus.

Very nice job 
Henry Pollet
7/18/2013 4:26:27 PM
Thanks for thème vidéo ! I Will receivethe leap Motion and of this week and used your code

Regards 
Iris Classon
7/19/2013 11:01:26 AM
Reply to: Henry Pollet
Sweet, and congrats! Let me know how it goes and feel free to ask questions! Here is a list of questions BTW: 16 questions on Leap Motion answered http://www.irisclasson.com/2013/07/02/stupid-question-200-216-16-questions-on-leap-motion-answered/ 
Shintaro Sasaki
8/3/2013 11:52:06 PM
I just want to tell you THANK YOU for the tutorial.  This is awesome.  You are AWESOME. 
Mario Esposito
8/7/2013 1:01:14 PM
love it! I want to tray that with Sensoria Gaming/Fitness http://08milluz.wordpress.com/2013/08/07/sensoria-gdk/ 
Mukesh Rawat
8/23/2013 2:15:06 AM
I downloaded the sample code provided by you for Leap Motion.I added the all api required to run application but it is showing error in below line:

var screen = _controller.CalibratedScreens.ClosestScreenHit(fingers[0]);
Error Details :
‘Leap controller could not contain a definition for ‘CalibratedScreens’ and no extension method ‘CalibratedScreens’ accepting a first argument of type ‘LeapController’ could be found (are your missing a using directive or an assembly reference?)

Can you help me out ?

Thanks. 
Mukesh Rawat
8/26/2013 5:01:28 AM
Reply to: Mukesh Rawat
used 'locatedScreens' instead of 'CalibratedScreens' and it worked nicely. 
jayesh jain
8/31/2013 12:11:22 PM
well,I am zero at c#.And unfortunately i have just got an assignment where I have to design a gesture based powerpoint presentation?

Can any body guide me..i am absolute begineer at it.. 
Bjørn
9/11/2013 4:45:32 AM
Hej,
I have a question about the Leap Motion Controller used as a mouse. I'm writing my bachelor thesis and I need exactly that :D. I watched your videos above and also downloaded the code. You 've said that the code in the "LeapAsMouse" Class is absolutely enough to enable this feature. Would this work the same way in C++?
I'm more a java programmer than a C++/C# programmer so maybe you can help me.

Många hälsningar 
Prachi Gujar
10/2/2013 2:58:38 AM
i am creating new assembly file .dll which i will be using in maxscript. how should i add leap.dlll and leapCsharp.dll in my assembly .dll file.. (c# code) 
Iris Classon
10/3/2013 1:40:24 AM
Reply to: Prachi Gujar
I haven't worked with maxscript before, but if its is an 'ordinary' .Net application then add the C# dll's and set copy to output always.

If you can give me some more information I might be able to better help you!

I (and a fellow dev) are publishing a course on developing for Leap Motion in C# next week, I'll email you once the course is out, there is a free trial where the course is published ( www.pluralsight.com ) :) It's a very good course that covers both a simple example, and a more complete example. 
Mina Metias
11/29/2013 11:01:08 AM
Thank you, for the brief - but however extremely efficient- tutorial :) 
vivian
12/4/2013 11:53:27 PM
Hi, encountered with 2 errors and the programme can't be run.. 

Error	1	'Leap.HandList' does not contain a definition for 'Empty' and no extension method 'Empty' accepting a first argument of type 'Leap.HandList' could be found (are you missing a using directive or an assembly reference?)	C:\Users\L31006\Desktop\Leap-Motion-master\Leap_WPF\Util\CustomListener.cs	33	29	Leap_WPF

Error	2	'Leap.Controller' does not contain a definition for 'locatedScreens' and no extension method 'locatedScreens' accepting a first argument of type 'Leap.Controller' could be found (are you missing a using directive or an assembly reference?)	C:\Users\L31006\Desktop\Leap-Motion-master\Leap_WPF\ViewModel\MainViewModel.cs	58	38	Leap_WPF


Do help if you can.. Thanks! 
student
12/5/2013 12:03:49 AM
No code errors but this was prompted and stop the program from running.

'The invocation of the constructor on type 'Leap_WPF.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9' 
Iris Classon
12/5/2013 6:23:01 AM
Reply to: student
Hi the tutorial was done on one of the first versions of the SDK and a lot has changed since then. I'll see if I can find some time and update this tutorial. 
Iris Classon
12/5/2013 6:26:13 AM
Reply to: vivian
The tutorial is on an old version of the SDK, the screen object is now deprecated and Empty is now called IsEmpty if I remember correctly. An  up to date tutorial I've made is here: http://pluralsight.com/training/courses/TableOfContents?courseName=developing-leap-motion-csharp
There is a free trial if you don't have a subscription. I'll make a new tutorial for the blog soon, and ping you once its done. Feel free to contact me if I can be of any help! 
DIego
12/16/2013 6:53:39 PM
Hey, thanks a lot for your tutorial.... but i have a problem... how i know which finger is doing a tap??? 
Iris Classon
12/17/2013 1:41:37 AM
Reply to: DIego
Thank you :) Try grabbing the Pointable, have a look at the documentation here: https://developer.leapmotion.com/documentation/Languages/CSharpandUnity/API/class_leap_1_1_screen_tap_gesture.html

Leap.ScreenTapGesture Class:
Properties
Vector 	Direction [get]
 	The direction of finger tip motion. 
 
Pointable 	Pointable [get]
 	The finger performing the screen tap gesture. 
 
Vector 	Position [get]
 	The position where the screen tap is registered. 
 
float 	Progress [get]
 	The progess value is always 1.0 for a screen tap gesture. 
Diego@ive.com.ar
12/17/2013 6:46:26 PM
Reply to: Iris Classon
yep... that class should works... thanks, i putt my hands to works...bye 
Iris Classon
12/18/2013 7:03:36 AM
Reply to: Diego@ive.com.ar
Best of luck, let me know if I can help any further 
Mykel K
12/18/2013 9:53:37 PM
Hi Iris, I downloaded and extracted the tutorial code and am getting two errors.
"Leap.Controller' does not contain a definition for 'CalibrateScreens and no extension method..." lines 58 and 86...
Do you have an idea of how to fix this error? As I am new to Leap Motion and want to really understand all help and advice are appreciated. Thank you! 
Michel K
12/18/2013 10:04:05 PM
Reply to: Mykel K
Also I did try the suggestion from above for the locatedScreens. But I still have the same error now indicating  no definition for locatedScreens. So any advice is greatly appreciated! Thanks! 
Iris Classon
12/19/2013 1:02:27 PM
Reply to: Michel K
AS I wrote the SDK is old and the screen methods are deprecated so the code will not run as is. The tutorial was made while the SDK was in beta and I haven't had the time to record new ones. I will do that as soon as I can, hopefully over Christmas. The course here: http://pluralsight.com/training/courses/TableOfContents?courseName=developing-leap-motion-csharp is up to date (by me and John). There is a free trial for Pluralsight. Give that a go, and I'll ping you as soon as I get this tutorial updated. 
Iris Classon
12/19/2013 1:02:33 PM
Reply to: Mykel K
AS I wrote the SDK is old and the screen methods are deprecated so the code will not run as is. The tutorial was made while the SDK was in beta and I haven't had the time to record new ones. I will do that as soon as I can, hopefully over Christmas. The course here: http://pluralsight.com/training/courses/TableOfContents?courseName=developing-leap-motion-csharp is up to date (by me and John). There is a free trial for Pluralsight. Give that a go, and I'll ping you as soon as I get this tutorial updated. 
Karina
9/11/2018 11:30:15 PM
Hi Iris

I'm new on Leap Motion Development, I was try to use a sample from https://developer-archive.leapmotion.com/documentation/v2/csharp/devguide/Project_Setup.html#windows-forms,

but  when I try to run it, the creation of a controller (Controller controller = new Controller();) 

shows the error message:
"The type initializer for Leap.LeapPINVOKE  threw an exception"

Please, help me 


Last modified on 2013-05-02