EventListener long touch and tap

I’m new to corona and I need to accomplish something like this:

When the user taps the screen => Calls Function screenTap

When the user taps and hold => Calls Function tapAndHold (once when it “began” and once when “ended”)

But I can’t find the way of creating this behaviour, If I add a “touch” and a “tap” event listener to the Runtime (I want to catch events on screen) the “tap” event always gets called after the “touch” event and that’s not what I want because both tapAndHold and screenTap gets called.

Any idea?? thanks!

You should program the whole thing into a single touch handler.  There are time values in the event table that’s passed in that you can use to measure the elapsed time between the start phase and the ended phase.  If the time between the two is short enough, call your tap handler, if it’s longer, call your tap and hold function.

Rob

Here is the code for your idea:  

local endedTime local beganTime function handler( event ) if event.phase == "began" then beganTime = event.time elseif event.phase == "ended" then endedTime = event.time if (endedTime - beganTime) \< 500 then print ("tap") else print ("touch") end end end

But really this is not what I’m looking for, I need the function “tapAndHold” to be called as soon as the event starts, the way I coded the eventHandler the function is only called when the event ends, and I need it to be called as soon as it starts… I can’t find a way of doing it so far… I spent some hours today and no luck so far…

Thanks!

The other thing to do is to set a timer that will fire after your predetermined tap time, and if you haven’t gotten an ended phase by then, call your tap and hold.

Rob

You should program the whole thing into a single touch handler.  There are time values in the event table that’s passed in that you can use to measure the elapsed time between the start phase and the ended phase.  If the time between the two is short enough, call your tap handler, if it’s longer, call your tap and hold function.

Rob

Here is the code for your idea:  

local endedTime local beganTime function handler( event ) if event.phase == "began" then beganTime = event.time elseif event.phase == "ended" then endedTime = event.time if (endedTime - beganTime) \< 500 then print ("tap") else print ("touch") end end end

But really this is not what I’m looking for, I need the function “tapAndHold” to be called as soon as the event starts, the way I coded the eventHandler the function is only called when the event ends, and I need it to be called as soon as it starts… I can’t find a way of doing it so far… I spent some hours today and no luck so far…

Thanks!

The other thing to do is to set a timer that will fire after your predetermined tap time, and if you haven’t gotten an ended phase by then, call your tap and hold.

Rob