1

I have implemented pointer events for canvas object. I need to know how we can detect finger count for touch events. Here is a piece of my code:

canvasObj.addEventListener( 'pointerenter', mouseEnterCall, false );
canvasObj.addEventListener( 'pointerdown',  mouseDownCall,  false );
canvasObj.addEventListener( 'pointermove',  mouseMoveCall,  false );
canvasObj.addEventListener( 'pointerup',    mouseUpCall,    false );
canvasObj.addEventListener( 'pointerout',   mouseOutCall,   false );

Appreciate your help.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Joe
  • 365
  • 2
  • 9
  • 24
  • Here is the piece of code. canvasObj.addEventListener('pointerenter', mouseEnterCall, false); canvasObj.addEventListener('pointerdown', mouseDownCall, false); canvasObj.addEventListener('pointermove', mouseMoveCall, false); canvasObj.addEventListener('pointerup', mouseUpCall, false); canvasObj.addEventListener('pointerout', mouseOutCall, false); – Joe Jan 06 '15 at 21:11
  • 1
    Sorry for the confusion. I'm trying to detect finger count on IE11 browser using above model. Is it possible or is there any other way? – Joe Jan 06 '15 at 21:19
  • I think I found the answer here. http://stackoverflow.com/questions/15811694/space-between-touch-points-on-ie10 – Joe Jan 06 '15 at 21:51

1 Answers1

2

There's no built-in property that gives you the current number of fingers (active pointers) on the screen. But here's some simple code that would achieve this:

var pointerCount = 0; //Stores current number of "active pointers"
window.addEventListener("pointerdown", addPointer, true); 
window.addEventListener("pointerup", removePointer, true); 
window.addEventListener("pointercancel", removePointer, true);
function addPointer(e) { pointerCount++ } 
function removePointer(e) { pointerCount-- }

You can modify addPointer to only count touch pointers, if that's what you want:

function addPointer(e) { if (e.pointerType === "touch") pointerCount++ } 

Note that you'll need to modify this code somewhat if you want to also support IE10, which has an earlier (prefixed) version of the standard.