Mobile Long Tap?

What would be the best way to detect a mobile long press?

I have a project where we use right click to open an context menu, but that excludes mobile clients so I need to have a smart way to detect if they press and held for a specific amount of time at a certain location.

i find it very odd that gestures have not become a native part of javascript.

15 years ago coming from being a flash developer and when I was learning/building some mobile stuff for the first time in unity , I rolled out my own gesture implementation and in the process realized besides the multi touch gestures , all others could be used on desktop as well. taps , long press , drags , swipes , flicks , and I did actually have a UI system that worked in this way with the same gesture engine for desktop and mobile.

In the years after that while doing javascript stuff, as things evolved I have always pondered why this doesnt just become native since there is no reason to need to have to have pointer events other than for perhaps doing some custom stuff like measuring tools or artistic stuff like paralax layers or things rotating toward a mouse direction… but for UI interaction and gestures … it should just be native. I remember searching for some library at the time and didnt find anything satisfactory , I have not looked again in a long time , but maybe someone has eventually coded some awesome gesture lib that works across all devices , has a small footprint , uses native pointer events and doesnt use 200 million other dependencies :wink:

if you find one let us know , or maybe someone else will post a link to one

Hammer.js used to be great for that

You know why? Copyright crap:)

1 Like

Maybe use a 2 finger tap instead? If you wanted to long press, I would think you would record the pointer down and target in your pointer observable or action and then record time and target (mesh) in the pointer up and if the targets are the same and the time is longer then threshold than it’s a long tap.

Yeah I for sure know how to do it manually, but was hoping there was some method that I did not know about that would work.

In the action manager we have the LongTapTrigger, but the pointerEvents we don’t have a long tap, so ill end up having to whip up a custom solution like you are talking about @ericwood73