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.
Keys explained
[X/Y/Z]: This is the position of the hand or finger relative to the Leap Motion Controller. (0, 0, 0) is the center of the field of view.
Delta[X/Y/Z]: This is the stabilized change in position since the last frame
Delta[X/Y/Z]_US: This is the unstabilized change is position since the last frame
DistToBound: How near/far the hand is to the outer-boundary of the field of view. Leap data becomes less reliable as your hands get closer to the boundary, so this variable can be used as a proxy to ignore unreliable data.
DataType: Can be "Forward" or "Post" sMsg (first parameter in the callback) is actually set to this. It seems silly to effectively include the parameter twice, so eventually I'll remove it. "Post" means that all "pointables" just went out of view, so the controller is no longer tracking data; conversely, "Forward" means pointable(s) are in view and so the controller is tracking and forwarding data. This method of forward/post is vital to AutoLeap because it is how you terminate a gesture chain.
ScaleFactor: Deprecated. It was used as a means to emulate pinching, but it sucked and the newest LeapSDK will natively support pinching. Direction TouchDistance and TouchZone are helpful tools to establish a virtual touch plane.
See Hand and Finger for additional information.
...
Last edited by Verdlin on 16 Dec 2014, 13:42, edited 3 times in total.
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.
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
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!
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!
@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.