Exemplo n.º 1
0
        private void MouseRightClick(HandState handRightState, IJoint rightHand, IJoint spineMid)
        {
            var zRightHandBodyDistance = spineMid.Position.Z - rightHand.Position.Z;

            if (zRightHandBodyDistance > 0.5f) // Right Hand Moving Cursor
            {
                if (handRightState == HandState.Open && startRightHandClickGestureState == null)
                {
                    startRightHandClickGestureState = new MouseGestureState(PHelper.CurrentTimeMillis());
                    startRightHandClickGestureState.oldCursorPosition = Cursor.Position;
                }
                else if (handRightState == HandState.Open && startRightHandClickGestureState != null)
                {
                    var cursorMoveDistance = PointDistance(Cursor.Position, startRightHandClickGestureState.oldCursorPosition);
                    if (cursorMoveDistance < 8)
                    {
                        var timeDiff = PHelper.CurrentTimeMillis() - startRightHandClickGestureState.TimeStamp;
                        if (timeDiff > 2000)
                        {
                            MouseControl.DoMouseRightClick();
                            startRightHandClickGestureState = null;
                        }
                    }
                    else
                    {
                        startRightHandClickGestureState = null;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void MouseScroll(IBody body, IJoint rightHand, IJoint spineMid)
        {
            var zRightHandBodyDistance = spineMid.Position.Z - rightHand.Position.Z;

            if (zRightHandBodyDistance > 0.5f)
            {
                if (body.HandRightState == HandState.Closed)
                {
                    if (startScrollGesture == null)
                    {
                        startScrollGesture = new MouseGestureState(PHelper.CurrentTimeMillis());
                        startScrollGesture.oldCursorPosition = Cursor.Position;
                        mouseInScroll = true;
                    }

                    if (startScrollClickGesture == null)
                    {
                        startScrollClickGesture = new MouseGestureState(PHelper.CurrentTimeMillis());
                        startScrollClickGesture.oldCursorPosition = Cursor.Position;
                    }
                    else
                    {
                        var currentTime = PHelper.CurrentTimeMillis();
                        var timeDiff    = currentTime - startScrollClickGesture.TimeStamp;
                        if (timeDiff > 1000)
                        {
                            MouseControl.ScrollClick();
                            startScrollGesture      = null;
                            startScrollClickGesture = null;
                            mouseInScroll           = false;
                        }
                    }
                }
                else if (body.HandRightState == HandState.Open)
                {
                    if (startScrollGesture != null)
                    {
                        var currentPosition = Cursor.Position;
                        var yMovement       = -1 * (currentPosition.Y - startScrollGesture.oldCursorPosition.Y);
                        var times           = 10;
                        MouseControl.Scroll(times);
                        startScrollGesture = null;
                        mouseInScroll      = false;
                    }
                }
                else
                {
                    //ignore
                }
            }
        }
Exemplo n.º 3
0
        private void MouseLeftClick(HandState handLeftState, IJoint leftHand, IJoint spineMid)
        {
            var zLeftHandBodyDistance = spineMid.Position.Z - leftHand.Position.Z;

            if (zLeftHandBodyDistance > 0.5f) // Right Hand Moving Cursor
            {
                if (handLeftState == HandState.Closed && startLeftHandClickGestureState == null)
                {
                    startLeftHandClickGestureState = new MouseGestureState(PHelper.CurrentTimeMillis());
                    startLeftHandClickGestureState.oldCursorPosition = Cursor.Position;
                }
                else if (handLeftState == HandState.Closed && startLeftHandClickGestureState != null)
                {
                    var cursorMoveDistance = PointDistance(Cursor.Position, startLeftHandClickGestureState.oldCursorPosition);
                    //Console.WriteLine(cursorMoveDistance);
                    if (cursorMoveDistance < 8)
                    {
                        MouseControl.DoMouseClick();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void LeftHandActions(IBody body, IJoint lefthand, IJoint spineMid)
        {
            //Point cursorPlanePosition = ConvertToDisplayCoordinates(lefthand.Position.X, lefthand.Position.Y);
            //this._previousCursorPosition = this._cursorPosition;
            //this._cursorPosition = cursorPlanePosition;
            //var haltCursorMove = PointDistance(_cursorPosition, _previousCursorPosition) < 5 ? true : false;
            float  x         = lefthand.Position.X - spineMid.Position.X + 0.3f;
            float  y         = spineMid.Position.Y - lefthand.Position.Y + 0.3f;
            Point  curPos    = Cursor.Position;
            double smoothing = 1 - cursorSmoothing;

            //if (!haltCursorMove)
            //MouseControl.SetCursorPos(curPos.X, curPos.Y);
            MouseControl.SetCursorPos((int)(curPos.X + (x * mouseSensitivity * screenWidth - curPos.X) * smoothing), (int)(curPos.Y + ((y + 0.25f) * mouseSensitivity * screenHeight - curPos.Y) * smoothing));
            alreadyTrackedPos = true;
            if (doClick && useGripGesture)
            {
                #region Drag With Left and Single Click
                if (body.HandLeftState == HandState.Closed)
                {
                    if (!mouseInDrag)
                    {
                        cursorSmoothing = 0.9999;
                    }
                    if (dragMouseGestureState == null)
                    {
                        dragMouseGestureState = new MouseGestureState(PHelper.CurrentTimeMillis());
                        dragMouseGestureState.oldCursorPosition = Cursor.Position;
                        dragMouseGestureState.oldHandPosition   = new SpacePoint(x, y, 0);
                    }
                    else
                    {
                        SpacePoint handCurrentPosition = new SpacePoint(x, y, 0);
                        var        distanceDiff        = PointDistance(dragMouseGestureState.oldHandPosition, handCurrentPosition);
                        if (distanceDiff > 0.09 && !mouseInDrag)
                        {
                            cursorSmoothing = CURSORSMOOTHING;
                            MouseControl.MouseLeftDown();
                            mouseInDrag = true;
                        }
                    }

                    if (clickMouseGestureState == null)
                    {
                        clickMouseGestureState = new MouseGestureState(PHelper.CurrentTimeMillis());
                        clickMouseGestureState.oldCursorPosition = Cursor.Position;
                        clickMouseGestureState.oldHandPosition   = new SpacePoint(x, y, 0);
                    }
                    if (doubleClickMouseGestureState == null)
                    {
                        doubleClickMouseGestureState = new MouseGestureState(PHelper.CurrentTimeMillis());
                        doubleClickMouseGestureState.oldCursorPosition = Cursor.Position;
                        doubleClickMouseGestureState.oldHandPosition   = new SpacePoint(x, y, 0);
                    }
                    //else
                    //{
                    //    var distanceDiff = PointDistance(doubleClickMouseGestureState.oldCursorPosition, Cursor.Position);
                    //    if (distanceDiff < 4)
                    //    {

                    //    }
                    //}
                }
                else if (body.HandLeftState == HandState.Open)
                {
                    cursorSmoothing = CURSORSMOOTHING;
                    if (mouseInDrag)
                    {
                        MouseControl.MouseLeftUp();
                        mouseInDrag           = false;
                        dragMouseGestureState = null;
                    }
                    else
                    {
                        if (clickMouseGestureState != null)
                        {
                            SpacePoint handCurrentPosition = new SpacePoint(x, y, 0);
                            var        distanceDiff        = PointDistance(clickMouseGestureState.oldHandPosition, handCurrentPosition);
                            //var timeDiff = PHelper.CurrentTimeMillis() -
                            if (distanceDiff < 0.05)
                            {
                                MouseControl.DoMouseClick();
                                Console.WriteLine("Mouse Double Click");
                            }
                            clickMouseGestureState = null;
                        }
                    }
                }
                //if (body.HandLeftState == HandState.Closed)
                //{
                //    if (!wasLeftGrip)
                //    {
                //        MouseControl.MouseLeftDown();
                //        wasLeftGrip = true;
                //    }
                //}
                //else if (body.HandLeftState == HandState.Open)
                //{
                //    if (wasLeftGrip)
                //    {
                //        MouseControl.MouseLeftUp();
                //        wasLeftGrip = false;
                //    }
                //}
                #endregion
            }
        }