Simple way to prevent an unintended double tap in Mixed Reality apps

Published on 11 June 2018 by Joost. Reading time: 2 minutes.

This is an easy and simple tip, but one that I use in almost every Mixed Reality app at one point. It’s mostly applicable to HoloLens: especially new users tend to double (triple, or even more) tap when the are operating an app, because the gestures are new. This can lead to undesirable and confusing results, especially with toggles. So it can help a little to ‘dampen out’ those double clicks.

I created this very simple helper class called DoubleClickPreventer:

using UnityEngine; 

namespace HoloToolkitExtensions.Utilities 
    public class DoubleClickPreventer 
        private readonly float _clickTimeOut; 
        private float _lastClick; 
        public DoubleClickPreventer(float clickTimeOut = 0.1f) 
            _clickTimeOut = clickTimeOut; 
        public bool CanClick() 
            if (!(Time.time - _lastClick < _clickTimeOut)) 
                return false; 
            _lastClick = Time.time; 
            return true; 


Basically, every time you ask it it you can click, it checks if a set amount of time (default 0.1 second) has passed since the last click. It’s usage is pretty simple: just make a behaviour that implements IInputClickHandler (from the Mixed Reality Toolkit) as usual, define a DoubleClickPreventer member, create it in Start like this:


_doubleClickPreventer = new DoubleClickPreventer(0.5f);


and then in your OnInputClicked implementation use something like this: 


if (_doubleClickPreventer.CanClick()
 // do stuff


and this will prevent a second click happening more than once every half second.
I made a little demo project, in which one cube has a GuardedClicker behaviour, that implements the DoubleClickPreventer, and the other a SimpleClickPreventer, that just registers every click.




If you click like a maniac for about a second or two on both cubes, you will clearly see a different result.

Note: the InputClickedEventData that you get in OnInputClicked.IInputClickHandler contains a “TapCount” property, but I have found that’s usually just 1, and however that does not stop the ‘stuttery double tap’ we are trying to prevent here. Also, this solution allows for fast clicks on separate objects, but not fast clicks on the same object.

The demo project (although it’s very little) can be downloaded here.

Tags: Mixed Reality


Published by Joost on 11 June 2018

Joost van Schaik has 25 years IT experience and has been working in Geographical Information Systems, Azure Cloud development and Cross-Platform Mobile (Xamarin) Development. He is currently focusing on Mixed Reality: he was a HoloLens and Windows Mixed Reality pioneer since the very beginning, authored 2 apps in the store and several for various customers. He is an active community member, has been blogging about a plethora of technical subjects since 2007 and as a result, has been awarded Microsoft Most Valuable Professional since 2011.


Comments? Share them below

Learn more about ETTU

And the way we work