#Hololens – How to detect AirTap and Click actions using #HoloToolkit (updated!)

Hello!

During the last few months, HoloToolkit has evolved a lot. Some of the changes in the Toolkit make some of my blog samples as non-valid. For example, basic actions such as detecting an AirTap. In today’s post, I’ll quickly explain how to implement the AirTap or Click.

We start with the basics with these steps

  • Create a 3D project in Unity3D
  • Configure project to support HoloLens projects
  • Clean Scene elements
  • Import HoloToolkit package
  • Add
    • HololensCamera
    • SpatialMapping
    • CursorWithFeedback
  • Add Empty element, Managers
    • Add existing scripts
      • Gaze Managers
      • Gaze Stabilizer
      • Input Manager
  • Add Empty element, HoloCollection
    • Add 3D elements
      • Cube
        • Position, x:0 y:0 z:2
        • Rotation, x:0 y:0 z:0
        • Scale, x:0.3 y:0.3 z:0.3

This is the basic process to create a Hololens project in Unity3D.  Now let’s associate a script to the Cube that detects some user actions of the user, such as for example the AirTap. For this example, I will call the script “CubeManager.cs“. This is the source code of the script:

using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class CubeManager : MonoBehaviour, IInputClickHandler, IInputHandler
{
  public void OnInputClicked(InputClickedEventData eventData)
  {
    // AirTap code goes here
  }
  public void OnInputDown(InputEventData eventData)
  { }
  public void OnInputUp(InputEventData eventData)
  { }
}

To capture AirTaps actions, we need to implement the “IInputClickHandler” interface. In the OnInputClicked(InputClickedEventData eventData) method we can perform actions when the user AirTap on the element. In the same way, if we implement the interface “IInputHandler” we can capture events “Click/Tap Down” and “Click/Tap Up” in an element of our app.

Note: Besides the AirTap action, this example serves to Click action on the Hololens clicker.

IMHO, I find it a much more ‘clean’ way this way of working with events using interfaces. Although there is still a way to go. In my next post, I will show how to work with hands and Hololens, for this sample the approach is not interface driven.

The sample code can be downloaded from GitHub (link)

Greetings @ Toronto

El Bruno

References

32 comments

  1. Hello!
    I want to detect user interaction(gaze,gesture,voice) in an existing app (Galaxy Explorer) and export them in a file or DB. This code can help me to do what I want?

    Thank you,
    Elena Matsi

    Like

    1. Hi Elena
      yes, you can use this code as a base for your request. However, please review the Galaxy Explorer code I think they use a different version of Holotoolkit
      Regards
      -Bruno

      Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.