AutoLeap: Leap Motion Module - AHK control with your hands!

Post your working scripts, libraries and tools for AHK v1.1 and older
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
Contact:

AutoLeap: Leap Motion Module - AHK control with your hands!

09 Dec 2014, 16:45

If you don't already know what a Leap Motion Controller is, then watch this video: http://www.youtube.com/watch?v=_d6KuiuteIA

This is an exciting, new piece of technology that has lots of potential. The Leap SDK supports C++, Java, Unity, CSharp, and a few other prominent languages. That's great, but it doesn't support AutoHotkey! The goal of AutoLeap is to do just that.

And it's already successful. The first AutoHotkey-based program went live on Airspace a few months ago (developed by yours truly). You can view the application here: https://airspace.leapmotion.com/apps/wi ... er/windows

This is a two-layer module with a small C++ application being the inner layer and AutoHotkey (AutoLeap.ahk) being the outer layer. The inner layer has a callback in a thread from msvcr120.dll. The callback is invoked when a "pointable" object comes into view of the controller. The rate at which the callback is invoked is directly dependent upon your frame rate, meaning that if you get 60 FPS then the callback is called every ~16.67ms (1000 ms / 60 frames). This is important to understand because this means your script should take no longer than 16.67 (or 1000 ms / FrameRate ) to execute it's "OnFrame" events or else lag will occur.

Q: Couldn't the lag be avoided by using a buffer?
A: One day, I hope so. Currently the limitation revolves around the fact that the C++ application uses SendMessage (which waits for a return value before proceeding) to forward data to the AHK script (AutoLeap).

Included in this post is a sample which demonstrates various ways to use this Leap Motion Controller with AutoHotKey. It's important to know the basics, and here they are:
  • Initialize an AutoLeap object like this: vLeap := new AutoLeap("LeapSample_MsgHandler")
  • Callback must have the following parameters: LeapSample_MsgHandler(sMsg, ByRef rLeapData, ByRef rasGestures, ByRef rsOutput)
  • rLeapData is your friend. It is an EasyIni object with sections for all hands and fingers within view of the controller.
Fork the C++ module here: https://aatoz.visualstudio.com/DefaultC ... a=contents
Fork the AHK module here: https://github.com/Aatoz/AutoHotkey/tre ... s/AutoLeap

Download the AHK sample, AutoLeap module (including C++ forwarder) here: https://www.dropbox.com/s/z366t0mjlu6ju ... e.zip?dl=0

Here's an exhaustive list of data available through rLeapData, but it may become dated as the module is developed further.
Spoiler
Last edited by Verdlin on 16 Dec 2014, 13:42, edited 3 times in total.
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31

Re: AutoLeap: Leap Motion Controller Module

09 Dec 2014, 16:48

I have one of these! Can't wait to try this out.
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
Contact:

Re: AutoLeap: Leap Motion Controller Module

10 Dec 2014, 07:17

Updated post to include link to a sample script. This should help you get started. It should work OOB. Simply unzip and run Leap_Sample.ahk from AutoHotkey.exe

Let me know if you have any issues, jigga. I'll be checking this post daily and frequently.
User avatar
lifeweaver
Posts: 144
Joined: 10 May 2014, 05:57
Location: OH
Contact:

Re: AutoLeap: Leap Motion Module - AHK control with your hands!

09 Apr 2016, 21:25

Nice post Verdlin,

When I try to start the Leap_Sample.ahk from your dropbox it says 'Call to nonexistent function':
---------------------------
Leap_Sample.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: st_glue(rasGestures, ", ")

Line#
132: {
133: g_vLeapMsgProcessor.m_hTriggerGestureFunc.(rLeapData, rasGestures)
136: if (!g_vLeapMsgProcessor.m_bActionHasStarted)
137: g_vLeapMsgProcessor.m_bActionHasStarted := g_vLeapMsgProcessor.m_bCallbackCanStop
139: if (g_vLeap.IsMakingFist(rLeapData) && g_vLeapMsgProcessor.m_bFistMadeDuringThreshold)
140: g_vLeapMsgProcessor.m_bCallbackCanStop := true
141: }
---> 143: sGesture := st_glue(rasGestures, ", ")
144: if (sGesture == "")
145: Return
147: For sec,aData in g_vLeap.m_vGesturesIni
148: {
149: if (sGesture = aData.Gesture)
150: {
151: bGestureExists := true

The program will exit.
---------------------------
OK
---------------------------

Where can I find this function, I didn't see it anywhere?
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
Contact:

Re: AutoLeap: Leap Motion Module - AHK control with your hands!

11 Apr 2016, 08:46

lifeweaver wrote:Nice post Verdlin,

When I try to start the Leap_Sample.ahk from your dropbox it says 'Call to nonexistent function':
---------------------------
Leap_Sample.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: st_glue(rasGestures, ", ")

Line#
132: {
133: g_vLeapMsgProcessor.m_hTriggerGestureFunc.(rLeapData, rasGestures)
136: if (!g_vLeapMsgProcessor.m_bActionHasStarted)
137: g_vLeapMsgProcessor.m_bActionHasStarted := g_vLeapMsgProcessor.m_bCallbackCanStop
139: if (g_vLeap.IsMakingFist(rLeapData) && g_vLeapMsgProcessor.m_bFistMadeDuringThreshold)
140: g_vLeapMsgProcessor.m_bCallbackCanStop := true
141: }
---> 143: sGesture := st_glue(rasGestures, ", ")
144: if (sGesture == "")
145: Return
147: For sec,aData in g_vLeap.m_vGesturesIni
148: {
149: if (sGesture = aData.Gesture)
150: {
151: bGestureExists := true

The program will exit.
---------------------------
OK
---------------------------

Where can I find this function, I didn't see it anywhere?
Hey, lifeweaver. Sorry about the mistake. This is the "String Thins" library made by Tidbit. It goes in your "lib" folder, so that's why it wasn't included in the package. Here's the link to String Things: http://www.autohotkey.net/~tidbit/StringThings/ST.ahk
User avatar
lifeweaver
Posts: 144
Joined: 10 May 2014, 05:57
Location: OH
Contact:

Re: AutoLeap: Leap Motion Module - AHK control with your hands!

13 Apr 2016, 03:59

Thanks!

Looks like it was no mistake, I see you mentioned it in your credits on the Github project, sorry to bother on that dependency.
I understand how, once you have something in your lib, it's easy to forget that not everyone has it!

Just for anyone else who had trouble, I additionally needed to go find:
class_EasyIni: https://autohotkey.com/board/topic/9157 ... -retained/
Str_MeasureText: https://raw.githubusercontent.com/Aatoz ... ib/Str.ahk
WAnim_SlideIn: https://raw.githubusercontent.com/Aatoz ... /WAnim.ahk
LV_GetSel: https://raw.githubusercontent.com/Aatoz ... Lib/LV.ahk

@Verdlin
I liked the idea of having a AutoHotkey make file, have you though of downloading these libraries a part of it into a `%A_ScriptDir%\Lib\`?
Verdlin
Posts: 63
Joined: 04 Oct 2013, 08:55
Contact:

Re: AutoLeap: Leap Motion Module - AHK control with your hands!

14 Apr 2016, 13:24

lifeweaver wrote:Thanks!

Looks like it was no mistake, I see you mentioned it in your credits on the Github project, sorry to bother on that dependency.
I understand how, once you have something in your lib, it's easy to forget that not everyone has it!

Just for anyone else who had trouble, I additionally needed to go find:
class_EasyIni: https://autohotkey.com/board/topic/9157 ... -retained/
Str_MeasureText: https://raw.githubusercontent.com/Aatoz ... ib/Str.ahk
WAnim_SlideIn: https://raw.githubusercontent.com/Aatoz ... /WAnim.ahk
LV_GetSel: https://raw.githubusercontent.com/Aatoz ... Lib/LV.ahk

@Verdlin
I liked the idea of having a AutoHotkey make file, have you though of downloading these libraries a part of it into a `%A_ScriptDir%\Lib\`?
Thanks a lot for the feedback! I truly appreciate it.

Yeah, I use the std lib heavily because I dislike code cloning -- even between entirely separate projects. I think providing a lib folder with this module is a great idea, and I'll do that soon.

For the record, the make file provided requires some customization (you can see absolute paths to my VS project) but it's not too bad.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 130 guests