How to detect two-finger tap in Corona?

How can I detect when a tap is done with two fingers? The tap event can tell the number of taps, but not how many touches were involved in the event. Is there any way to figure it out? I have multitouch enabled in my Corona App and testing on device. I’m porting an native app from iOS to Corona to deploy to Android devices. The application simulates a left-button mouse click on a single-finger tap. And, a right-button mouse click on a double-finger tap. 

I must be missing something dead obvious but I can’t find a way to do it for the life of me. I’m dead in the water. Please, any help would be appreciated!

Hi @la_luisartola,

For this, I think you’ll need to do a bit of custom work using a “touch” listener, not a “tap” listener. While the tap listener can report the number of taps (event.numTaps), you’ll need to use the touch listener, with multitouch, and the “event.id” to distinguish between each touch point. Then, you should be able to determine the location of each touch point (to ensure that the “location range” between the first and second “tap” are close enough to each other) and use “event.time” to make sure this entire user action is valid… meaning, fast enough between each motion to consider it a two-finger “tap”.

http://docs.coronalabs.com/api/event/touch/index.html

Hope this helps,

Brent

Thanks Brent. I’ll give this idea a try.

I think I have a stable solution based on this idea. Though it is more convoluted than I thought it would be. I’ll be posting some sample code soon. I’m interested in getting feedback, somehow I’m still hoping I’m missing something obvious and I’m just overcomplicating matters - given that most other things in Corona are simple and straightforward.

There is a number of ways to do this, but the simplest I can think of is to check the start and end time of separate taps with a couple of display objects. As Brent says, you can’t use the tap listener because that would only allow detection of a double tap because the listener only fires after the user has completed the tap action.

When a touch event starts create a display object and set the focus of the touch to it. This is your first finger’s handler object.

When a second touch event starts create a second display object and set the focus of the touch to it. This is you second finger’s touch handler object.

Now, in the end event of the first touch listener check to see if a second handler object has been created. If it has, set a variable value in it to check for a double tap.

In the end event of the second touch listener, if that variable is set, check the distance between the two touches and their end times. If they are close enough, both in distance and time, then you have a two finger tap.

You could store this information in another object and check against it in the end event to determine if it is a single, double, triple or more tap.

Hi @la_luisartola,

For this, I think you’ll need to do a bit of custom work using a “touch” listener, not a “tap” listener. While the tap listener can report the number of taps (event.numTaps), you’ll need to use the touch listener, with multitouch, and the “event.id” to distinguish between each touch point. Then, you should be able to determine the location of each touch point (to ensure that the “location range” between the first and second “tap” are close enough to each other) and use “event.time” to make sure this entire user action is valid… meaning, fast enough between each motion to consider it a two-finger “tap”.

http://docs.coronalabs.com/api/event/touch/index.html

Hope this helps,

Brent

Thanks Brent. I’ll give this idea a try.

I think I have a stable solution based on this idea. Though it is more convoluted than I thought it would be. I’ll be posting some sample code soon. I’m interested in getting feedback, somehow I’m still hoping I’m missing something obvious and I’m just overcomplicating matters - given that most other things in Corona are simple and straightforward.

There is a number of ways to do this, but the simplest I can think of is to check the start and end time of separate taps with a couple of display objects. As Brent says, you can’t use the tap listener because that would only allow detection of a double tap because the listener only fires after the user has completed the tap action.

When a touch event starts create a display object and set the focus of the touch to it. This is your first finger’s handler object.

When a second touch event starts create a second display object and set the focus of the touch to it. This is you second finger’s touch handler object.

Now, in the end event of the first touch listener check to see if a second handler object has been created. If it has, set a variable value in it to check for a double tap.

In the end event of the second touch listener, if that variable is set, check the distance between the two touches and their end times. If they are close enough, both in distance and time, then you have a two finger tap.

You could store this information in another object and check against it in the end event to determine if it is a single, double, triple or more tap.