Attributes:
Extends Gesture()
The KeyTapGesture class represents a tapping gesture by a finger or tool.
A key tap gesture is recognized when the tip of a finger rotates down toward the palm and then springs back to approximately the original postion, as if tapping. The tapping finger must pause briefly before beginning the tap.
Key tap gestures are discrete. The KeyTapGesture object representing a tap always has the state, “stop”. Only one KeyTapGesture object is created for each key tap gesture recognized.
An uninitialized KeyTapGesture object is considered invalid. Get valid instances of the KeyTapGesture class from a Frame object or a gesture event listener.
The following example illustrates how to get gesture objects from a frame of tracking data:
var controller = Leap.loop({enableGestures: true}, function(frame){
if(frame.valid && frame.gestures.length > 0){
frame.gestures.forEach(function(gesture){
switch (gesture.type){
case "circle":
console.log("Circle Gesture");
break;
case "keyTap":
console.log("Key Tap Gesture");
break;
case "screenTap":
console.log("Screen Tap Gesture");
break;
case "swipe":
console.log("Swipe Gesture");
break;
}
});
}
});
You can also add a listener callback to a Controller object. Your callback is called for each gesture object in each device frame:
var controller = Leap.loop({enableGestures: true}, function(frame){
//... handle frame data
});
controller.on("gesture", function(gesture){
//... handle gesture object
});
Constructs an invalid KeyTapGesture object.
An uninitialized KeyTapGesture object is considered invalid. Get valid instances of the KeyTapGesture class from a Frame() object.
Type: | number[] |
---|
The direction of finger tip motion.
if(gesture.type == "keyTap"){
var direction = gesture.direction;
}
Type: | number |
---|
The elapsed duration of the recognized movement up to the frame containing this Gesture object, in microseconds.
var duration = gesture.duration;
The duration reported for the first Gesture in the sequence (with the start state) will typically be a small positive number since the movement must progress far enough for the Leap to recognize it as an intentional gesture.
Type: | Array |
---|
The list of hands associated with this Gesture, if any.
var controller = Leap.loop({enableGestures: true}, function(frame){
if(frame.valid && frame.gestures.length > 0){
frame.gestures.forEach(function(gesture){
var handIds = gesture.handIds;
handIds.forEach(function(handId){
var hand = frame.hand(handId);
});
});
}
});
If no hands are related to this gesture, the list is empty.
Type: | number |
---|
The gesture ID.
All Gesture objects belonging to the same recognized movement share the same ID value. Use the ID value with the Frame.gesture() method to find updates related to this Gesture object in subsequent frames.
var gestureIdOfInterest = gesture.id;
Type: | Array |
---|
The list of fingers and tools associated with this Gesture, if any.
var controller = Leap.loop({enableGestures: true}, function(frame){
if(frame.valid && frame.pointables.length > 0){
frame.gestures.forEach(function(gesture){
var pointableIds = gesture.pointableIds;
pointableIds.forEach(function(pointableId){
var pointable = frame.pointable(pointableId);
});
});
}
});
If no Pointable objects are related to this gesture, the list is empty.
Type: | number[] – a 3-element array representing a vector |
---|
The position where the key tap is registered.
if(gesture.type == "keyTap"){
var position = gesture.position;
}
Type: | String |
---|
The gesture state. KeyTapGesture objects always have the state: “stop”.
var state = gesture.state;
Type: | String |
---|
The gesture type. In this case: “keyTap”.
var controller = Leap.loop({enableGestures: true}, function(frame){
if(frame.valid && frame.gestures.length > 0){
frame.gestures.forEach(function(gesture){
switch (gesture.type){
case "circle":
console.log("Circle Gesture");
break;
case "keyTap":
console.log("Key Tap Gesture");
break;
case "screenTap":
console.log("Screen Tap Gesture");
break;
case "swipe":
console.log("Swipe Gesture");
break;
}
});
}
});