/* some project examples about Kinect with C# language */
private bool CheckForClickHold(Joint hand)
{
// This does one handed click when you hover for the allotted time. It gives a false positive when you hover accidentally.
var x = hand.Position.X;
var y = hand.Position.Y;
var screenwidth = (int)SystemParameters.PrimaryScreenWidth;
var screenheight = (int)SystemParameters.PrimaryScreenHeight;
var clickwidth = (int)(screenwidth * ClickHoldingRectThreshold);
var clickheight = (int)(screenheight * ClickHoldingRectThreshold);
var newClickHold = new Rect(x - clickwidth, y - clickheight, clickwidth * 2, clickheight * 2);
if (_clickHoldingLastRect != Rect.Empty)
{
if (newClickHold.IntersectsWith(_clickHoldingLastRect))
{
if ((int)_clickHoldingTimer.ElapsedMilliseconds > (ClickDelay.Value * 1000))
{
_clickHoldingTimer.Stop();
_clickHoldingLastRect = Rect.Empty;
return true;
}
if (!_clickHoldingTimer.IsRunning)
{
_clickHoldingTimer.Reset();
_clickHoldingTimer.Start();
}
return false;
}
_clickHoldingTimer.Stop();
_clickHoldingLastRect = newClickHold;
return false;
}
_clickHoldingLastRect = newClickHold;
if (!_clickHoldingTimer.IsRunning)
{
_clickHoldingTimer.Reset();
_clickHoldingTimer.Start();
}
return false;
}