I use the following code to get the touch began and touch end:
DateTime TapCurrentTimeUTC;
DateTime TapReleasedTimeUTC;
TimeSpan TapRemainingTimeUTC = TimeSpan.Zero;
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
TouchPanel.EnabledGestures = GestureType.Tap | GestureType.FreeDrag | GestureType.DragComplete;
}
protected override void Update(GameTime gameTime)
{
Touchcollection = TouchPanel.GetState();
if (Touchcollection.Count > 0)
{
if (Touchcollection[0].State == TouchLocationState.Released)
{
TapReleasedTimeUTC = DateTime.UtcNow;
TapRemainingTimeUTC = TapReleasedTimeUTC - TapCurrentTimeUTC;
}
if (Touchcollection[0].State == TouchLocationState.Pressed)
{
TapCurrentTimeUTC = DateTime.UtcNow;
TapRemainingTimeUTC = TimeSpan.Zero;
}
}
base.Update(gameTime);
}
while (TouchPanel.IsGestureAvailable)
{
GestureSample gs = TouchPanel.ReadGesture();
switch (gs.GestureType)
{
case GestureType.Tap:
// Then I use
break;
case GestureType.FreeDrag:
break;
case GestureType.DragComplete:
break;
}
}
When I tap on the display screen the Touchcollection State is TouchLocationState.Pressed and when I don´t touch the display anymore then the Touchcollection State is TouchLocationState.Released.
TapRemainingTimeUTC is the duration of the tap on the display screen.
Afterwards case GestureType.Tap is executed and I use TapRemainingTimeUTC there.