2

I'm building a simple web game with mouse and touch support. Based on the accepted answer to JavaScript mapping touch events to mouse events I copy-pasted their code (with a couple of modifications).

I'm mapping the first touch the user makes to a left-click event, and the second they make (with the first touch held down) to a right-click event. Like so:

function touchHandler(event){
var touches = event.changedTouches;
var first   = touches[0];
var type    = "";

switch(event.type){
    case "touchstart" : type = "mousedown"; break;
    case "touchmove"  : type = "mousemove"; break;
    case "touchend"   : type = "mouseup";   break;
    default:return;
}
var button = 0;
if(first.identifier >= 1)
    button = 2;
document.getElementById("foo").innerHTML = first.identifier; //my "debug statement"
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type,true,true,window,1,
                              first.screenX,first.screenY,
                              first.clientX,first.clientY,false,
                              false,false,false,button,null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault(); }

Here's the issue: my "debug statement" (see the code) revealed that identifier was being correct in the emulator modes in chrome, as well as on my android phone and MS Surface. But on my iPad? 1862464270, and counting. Clearly, I do not have that many fingers.

This issue occurs running either Chrome or Safari, but only on my iPad. Everything works fine on the other systems I've used for testing.

Does anyone have an idea of what might be causing this issue? Has anyone else encountered strange event.identifier behavior?

Community
  • 1
  • 1
Vyross
  • 109
  • 1
  • 12
  • I am having the exact same issue! Did you end up finding out any more on this? Any help would be greatly appreciated! – beefchimi Sep 13 '14 at 02:34
  • 1
    This ended up providing some clarity for me. Perhaps it will help you as well: http://dropshado.ws/post/45694832906/touch-identifier-0 – beefchimi Sep 13 '14 at 03:33

0 Answers0