Ejemplo n.º 1
0
        /// <summary>
        /// Stops mouse gesture recording and tries to recognize the gesture
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Mouse event data</param>
        public void EndGesture(object sender, EventArgs e)
        {
            working = false;

            //check minimal length
            //TODO change minimal length checking  - does not work for gesture LeftRight, etc...
            if (mouseMoveSegments.Count * mouseMoveSegmentLength < minGestureSize)
            {
                //too short for mouse gesture - send regular right mouse click
                mf.Enabled = false;
                WinAPI.MouseInputEmulation.SendRightMouseClick();
                Application.DoEvents();
                mf.Enabled = true;

                return;
            }

            //try recognize mouse gesture
            MouseGesture gesture = RecognizeGesture();

            if (gesture != MouseGesture.Unknown)
            {
                RaiseGestureEvents(gesture);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Recognize gesture from the recorded data
        /// </summary>
        /// <returns>Returns MouseGesture or MouseGesture.Unknown if no gesture is recognized.</returns>
        /// <remarks>
        /// Funtion counts the number of unknown segments before the gestures,
        /// the number of segments in the gestures and the number of unknown segments
        /// after the gestures. These counts are keystone for the gesture recognition.
        /// </remarks>
        private MouseGesture RecognizeGesture()
        {
            int index = 0;


            int unknownSegmentsBefore = CountMouseMoveSegments(ref index, MouseMoveSegment.SegmentDirection.Unknown);

            MouseMoveSegment.SegmentDirection firstSegmentDirection;
            int firstGestureLenght = CountMouseMoveSegments(ref index, out firstSegmentDirection);


            int unknownSegmentsMiddle = CountMouseMoveSegments(ref index, MouseMoveSegment.SegmentDirection.Unknown);

            MouseMoveSegment.SegmentDirection secondSegmentDirection = MouseMoveSegment.SegmentDirection.Unknown;
            int secondGestureLength = 0;
            int unknownSegmentAfter = 0;

            //if complex gesture are enabled count segments for the second gesture
            if (enableComplexGestures)
            {
                secondGestureLength = CountMouseMoveSegments(ref index, out secondSegmentDirection);

                unknownSegmentAfter = CountMouseMoveSegments(ref index, MouseMoveSegment.SegmentDirection.Unknown);
            }

            //if there are some segments left, the recorded data does not contain valid mouse gesture
            MouseMoveSegment.SegmentDirection nextSegment;
            if (CountMouseMoveSegments(ref index, out nextSegment) > 0)
            {
                return(MouseGesture.Unknown);
            }

            //recognize firs gesture
            MouseGesture firstGesture =
                RecognizeSimpleGesture(unknownSegmentsBefore, firstGestureLenght,
                                       unknownSegmentsMiddle, firstSegmentDirection);

            //if complex gesture are enabled continue with second gesture
            MouseGesture secondGesture;

            if ((enableComplexGestures) && (secondGestureLength > 0))
            {
                secondGesture = RecognizeSimpleGesture(unknownSegmentsMiddle, secondGestureLength,
                                                       unknownSegmentAfter, secondSegmentDirection);

                return(RecognizeComplexGeasture(firstGesture, secondGesture));
            }
            else
            {
                return(firstGesture);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recognizes complex MouseGesture from two simple gestures
        /// </summary>
        /// <param name="firstGesture">First simple gesture.</param>
        /// <param name="secondGesture">Second simple gesture</param>
        /// <returns>Returns complex MouseGesture or MouseGesture.Unknown if no gesture is recognized.</returns>
        protected MouseGesture RecognizeComplexGeasture(MouseGesture firstGesture, MouseGesture secondGesture)
        {
            if (firstGesture == MouseGesture.Unknown || secondGesture == MouseGesture.Unknown)
            {
                return(MouseGesture.Unknown);
            }

            //treats two simple gesture with the same direction with some unknown
            //segments between them as valid simple gesture
            //TODO consider disabling this
            if (firstGesture == secondGesture)
            {
                return(firstGesture);
            }

            //see MouseGesture.cs for referecne how to compute complex gesture
            return(firstGesture | (MouseGesture)((int)secondGesture * 2));
        }
 /// <summary>
 /// Stops mouse gesture recording and tries to recognize the gesture
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e">Mouse event data</param>
 public void EndGesture(object sender, EventArgs e)
 {
     //check minimal length
     //TODO change minimal length checking  - does not work for gesture LeftRight, etc...
     if (distance < minGestureSize || gesture.Count == 0)
     {
         //too short for mouse gesture - send regular right mouse click
         mf.Enabled = false;
         WinAPI.MouseInputEmulation.SendRightMouseClick();
         Application.DoEvents();
         mf.Enabled = true;
     }
     else
     {
         GestureHandler temp = Gesture;
         if (temp != null)
         {
             MouseGestureEventArgs args = new MouseGestureEventArgs(gesture);
             temp(this, args);
         }
     }
     gesture = null;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes new instance of MouseGestureEventArgs
 /// </summary>
 /// <param name="gesture">The type of the gesture performed.</param>
 /// <param name="beginning">The point, where user started the gesture.</param>
 public MouseGestureEventArgs(MouseGesture gesture, Point beginning) : base()
 {
     Gesture   = gesture;
     Beginning = beginning;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Raises proper events
        /// </summary>
        /// <param name="gesture">Gesture performed.</param>
        private void RaiseGestureEvents(MouseGesture gesture)
        {
            if (gesture != MouseGesture.Unknown)
            {
                MouseGestureEventArgs eventArgs = new MouseGestureEventArgs(gesture, gestureStartLocation);

                //always raise general event
                RaiseGestureEvent(eventArgs);

                switch (gesture)
                {
                case MouseGesture.Up:
                    RaiseGestureUpEvent(eventArgs);
                    break;

                case MouseGesture.Right:
                    RaiseGestureRightEvent(eventArgs);
                    break;

                case MouseGesture.Down:
                    RaiseGestureDownEvent(eventArgs);
                    break;

                case MouseGesture.Left:
                    RaiseGestureLeftEvent(eventArgs);
                    break;
                }

                if (enableComplexGestures)
                {
                    switch (gesture)
                    {
                    case MouseGesture.UpDown:
                        RaiseGestureUpDownEvent(eventArgs);
                        break;

                    case MouseGesture.UpRight:
                        RaiseGestureUpRightEvent(eventArgs);
                        break;

                    case MouseGesture.UpLeft:
                        RaiseGestureUpLeftEvent(eventArgs);
                        break;

                    case MouseGesture.RightUp:
                        RaiseGestureRightUpEvent(eventArgs);
                        break;

                    case MouseGesture.RightDown:
                        RaiseGestureRightDownEvent(eventArgs);
                        break;

                    case MouseGesture.RightLeft:
                        RaiseGestureRightLeftEvent(eventArgs);
                        break;

                    case MouseGesture.DownUp:
                        RaiseGestureDownUpEvent(eventArgs);
                        break;

                    case MouseGesture.DownRight:
                        RaiseGestureDownRightEvent(eventArgs);
                        break;

                    case MouseGesture.DownLeft:
                        RaiseGestureDownLeftEvent(eventArgs);
                        break;

                    case MouseGesture.LeftUp:
                        RaiseGestureLeftUpEvent(eventArgs);
                        break;

                    case MouseGesture.LeftRight:
                        RaiseGestureLeftRightEvent(eventArgs);
                        break;

                    case MouseGesture.LeftDown:
                        RaiseGestureLeftDownEvent(eventArgs);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes new instance of MouseGestureEventArgs
 /// </summary>
 /// <param name="gesture">The gesture performed.</param>
 public MouseGestureEventArgs(MouseGesture mouseGesture) : base()
 {
     gesture = mouseGesture;
 }
 /// <summary>
 /// Starts new mouse gesture
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e">Mouse event data</param>
 /// <remarks>
 /// Functions is called on the RightButtonDown event of MouseMessageFilter.
 /// </remarks>
 public void BeginGesture(object sender, EventArgs e)
 {
     lastPoint = Cursor.Position;
     gesture   = new MouseGesture(lastPoint);
     distance  = 0;
 }