question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Double Tap recognition

See original GitHub issue

Hello,

I want to use a double Tap gesture. I noticed, that the InputClickedEventData provides a TapCount.

But when I try the follwoing, only the Signle Tap is displayed.

Am I missing something? Or do I need to set up some timer to recognize two single Taps in a short time?

    public void OnInputClicked(InputClickedEventData eventData)
    {
      if (eventData.TapCount > 1)
        Debug.Log("Double Tap");
      else
        Debug.Log("Single Tap");
    }

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
killerantzcommented, Jul 10, 2017

Honestly, if we have to check the tap count and wait for seconds to tell the difference between a single and double tap, then the double tap functionality is not really in place. If it were, there would be a DoubleTap Event and the system would handle all this. So it may be best to roll your own for now, it’s the same amount of code and less hassle.

private Coroutine _tapRoutine;
void Start()
{
    _gestureRecognizer = new GestureRecognizer();
    _gestureRecognizer.TappedEvent += GestureRecognizerOnTappedEvent;
    _gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap);
    _gestureRecognizer.StartCapturingGestures();
    _gestureRecognizer.TappedEvent += (source, tapCount, ray) =>
    {
            if (_tapRoutine == null)
            {
                _tapRoutine = StartCoroutine(TapTimer());
            }
            else
            {
                StopCoroutine(_tapRoutine);
                _tapRoutine = null;
                print("doubleTap!");
                Shoot();
            }
    };
}

private IEnumerator TapTimer()
{
      yield return new WaitForSeconds(0.3f);
      print("singleTap!");
      _tapRoutine = null;
      Shoot1();
}
1reaction
killerantzcommented, May 10, 2017

I have not been able to get double-tap to work with the IPointerClickHandler, I only get zeros as the clickCount. You’ll need to have EventSystem added to the scene for IPointerClickEvents to occur. Just add a UI button to the scene and the EventSystem comes in as well.

I was able to get double-taps to work using IInputClickHandler and OnInputClicked(InputClickedEventData eventData) though.

First thing is the GesturesInput is not setup to handle double-tap detection, so you need to add it to the recognizable gestures by opening HoloToolkit/UI/Scripts/InputSources/GesturesInput.cs

On line 46 add GestureSettings.DoubleTap to the gestureRecognizer like this.

gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.ManipulationTranslate | GestureSettings.Hold | GestureSettings.DoubleTap);

Then in the OnInputClicked handler look at the tapCount which should be 1 or 2. public virtual void OnInputClicked(InputClickedEventData eventData) { print(eventData.TapCount); }

Two events will fire on a double-tap (1 and 2), so if you want to capture both single-taps and double-taps on the same object, you will have to delay the single-tap execution to see if a double-tap does not immediately follow. I hope that makes sense.

Maybe there’s a part of the EventSystem that needs to register to listen for double taps to get the IPointer stuff working, but I haven’t dug that far into it yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DT0101 Design tip - Setting up single-tap and double-tap ...
The single-tap and double-tap recognition feature allows detecting actions similar to the single click and double click of a mouse. The ...
Read more >
How to detect a double tap gesture
The iOS UITapGestureRecognizer class has a built-in way to detect a double tap on any view. All you need to do is create...
Read more >
NeoReader Double-Tap Recognition : r/Onyx_Boox
In NeoReader, hand-written notes can be recognized by double-tapping on it. Is there a way to change the font size of the recognized...
Read more >
DoubleTap recognition in UITableView
I have setup a pair of UITapGestureRecognizers to try to catch single and double taps on a UITableView. When the tap handler is...
Read more >
Android Tap, Double Tap, Pan and Pinch Gestures ...
Android Tap, Double Tap, Pan and Pinch Gestures Recognising — part 1. How to use Android Gesture recognizers and handle view touch events ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found