Esempio n. 1
0
        public void StopControlling()
        {
            freeze_until = DateTime.Now;
            mouse_state  = MouseState.Idle;

            if (MouseButtons.RightPressed)
            {
                MouseButtons.RightUp();
            }
            if (MouseButtons.LeftPressed)
            {
                MouseButtons.LeftUp();
            }
        }
Esempio n. 2
0
        public void StopControlling()
        {
            lock (Helpers.locker)
            {
                freeze_until    = DateTime.Now;
                mouse_state     = MouseState.Idle;
                idle_start_time = DateTime.Now;

                if (MouseButtons.RightPressed)
                {
                    MouseButtons.RightUp();
                }
                if (MouseButtons.LeftPressed)
                {
                    MouseButtons.LeftUp();
                }
            }
        }
Esempio n. 3
0
        public bool OnKeyPressed(
            Key key,
            KeyState key_state,
            double speed_up,
            bool is_short_modifier_press,
            bool is_repetition,
            bool is_modifier,
            InputProvider input_provider)
        {
            // The application grabs control over cursor when modifier is pressed.
            if (key == Key.Modifier)
            {
                if (key_state == KeyState.Down)
                {
                    StartControlling();
                    return(true);
                }

                if (key_state == KeyState.Up)
                {
                    if (mouse_state == EyeTrackingMouse.MouseState.Idle)
                    {
                        return(false);
                    }

                    bool handled = true;
                    if (is_short_modifier_press)
                    {
                        input_provider.SendModifierDown();
                        input_provider.SendModifierUp();
                        handled = true;
                    }
                    StopControlling();
                    return(handled);
                }
            }

            if (mouse_state == EyeTrackingMouse.MouseState.Idle)
            {
                return(false);
            }

            if (key == Key.Unbound)
            {
                // The application intercepts modifier key presses. We do not want to lose modifier when handling unbound keys.
                // We stop controlling cursor when facing the first unbound key and send modifier keystroke to OS before handling pressed key.
                if (!is_modifier)
                {
                    input_provider.SendModifierDown();
                    StopControlling();
                }
                return(false);
            }

            var repetition_white_list = new SortedSet <Key> {
                Key.ScrollDown,
                Key.ScrollUp,
                Key.ScrollLeft,
                Key.ScrollRight,
                Key.CalibrateLeft,
                Key.CalibrateRight,
                Key.CalibrateUp,
                Key.CalibrateDown,
            };

            if (is_repetition && !repetition_white_list.Contains(key))
            {
                return(true);
            }

            if (key_state == KeyState.Down)
            {
                // Calibration
                int calibration_step = (int)(Options.Instance.calibration_step * speed_up);
                if (key == Key.CalibrateLeft)
                {
                    StartCalibration();
                    calibration_shift.X -= calibration_step;
                    freeze_until         = DateTime.Now.AddMilliseconds(Options.Instance.calibrate_freeze_time_ms);
                    statistics.OnCalibrate();
                }
                if (key == Key.CalibrateRight)
                {
                    StartCalibration();
                    calibration_shift.X += calibration_step;
                    freeze_until         = DateTime.Now.AddMilliseconds(Options.Instance.calibrate_freeze_time_ms);
                    statistics.OnCalibrate();
                }
                if (key == Key.CalibrateUp)
                {
                    StartCalibration();
                    calibration_shift.Y -= calibration_step;
                    freeze_until         = DateTime.Now.AddMilliseconds(Options.Instance.calibrate_freeze_time_ms);
                    statistics.OnCalibrate();
                }
                if (key == Key.CalibrateDown)
                {
                    StartCalibration();
                    calibration_shift.Y += calibration_step;
                    freeze_until         = DateTime.Now.AddMilliseconds(Options.Instance.calibrate_freeze_time_ms);
                    statistics.OnCalibrate();
                }

                // Scroll
                if (key == Key.ScrollDown)
                {
                    MouseButtons.WheelDown((int)(Options.Instance.vertical_scroll_step * speed_up));
                }
                if (key == Key.ScrollUp)
                {
                    MouseButtons.WheelUp((int)(Options.Instance.vertical_scroll_step * speed_up));
                }
                if (key == Key.ScrollLeft)
                {
                    MouseButtons.WheelLeft((int)(Options.Instance.horizontal_scroll_step * speed_up));
                }
                if (key == Key.ScrollRight)
                {
                    MouseButtons.WheelRight((int)(Options.Instance.horizontal_scroll_step * speed_up));
                }
            }

            // Mouse buttons
            if (mouse_state == MouseState.Calibrating &&
                (key == Key.LeftMouseButton || key == Key.RightMouseButton))
            {
                ShiftsStorage.Instance.AddShift(
                    new ShiftsStorage.Position(gaze_point.X, gaze_point.Y, left_eye, right_eye, head_position, head_direction),
                    calibration_shift);
                mouse_state = MouseState.Controlling;
            }

            if (key == Key.LeftMouseButton)
            {
                if (key_state == KeyState.Down)
                {
                    // Freeze cursor for a short period of time after mouse clicks to make double clicks esier.
                    MouseButtons.LeftDown();
                    freeze_until = DateTime.Now.AddMilliseconds(Options.Instance.click_freeze_time_ms);
                    statistics.OnClick();
                }
                else if (key_state == KeyState.Up)
                {
                    MouseButtons.LeftUp();
                }
            }

            if (key == Key.RightMouseButton)
            {
                if (key_state == KeyState.Down)
                {
                    // Freeze cursor for a short period of time after mouse clicks to make double clicks esier.
                    MouseButtons.RightDown();
                    freeze_until = DateTime.Now.AddMilliseconds(Options.Instance.click_freeze_time_ms);
                    statistics.OnClick();
                }
                else if (key_state == KeyState.Up)
                {
                    MouseButtons.RightUp();
                }
            }

            if (key == Key.ShowCalibrationView && key_state == KeyState.Down)
            {
                App.ToggleCalibrationWindow();
            }

            return(true);
        }
Esempio n. 4
0
        public bool OnKeyPressed(
            Key key,
            KeyState key_state,
            float speed_up,
            bool is_repetition,
            bool is_modifier,
            InputProvider input_provider)
        {
            // The application grabs control over cursor when modifier is pressed.
            if (key == Key.Modifier)
            {
                if (key_state == KeyState.Down)
                {
                    StartControlling();
                    return(true);
                }

                if (key_state == KeyState.Up)
                {
                    if (mouse_state == EyeTrackingMouse.MouseState.Idle)
                    {
                        return(false);
                    }

                    StopControlling();
                    return(true);
                }
            }

            if (mouse_state == EyeTrackingMouse.MouseState.Idle)
            {
                return(false);
            }

            if (key == Key.Unbound)
            {
                // The application intercepts modifier key presses. We do not want to lose modifier when handling unbound keys.
                // We stop controlling cursor when facing the first unbound key and send modifier keystroke to OS before handling pressed key.
                // This way key combinations like 'Win+E' remain available.
                if (!is_modifier)
                {
                    input_provider.SendModifierDown();
                    StopControlling();
                }
                return(false);
            }

            var repetition_white_list = new SortedSet <Key> {
                Key.ScrollDown,
                Key.ScrollUp,
                Key.ScrollLeft,
                Key.ScrollRight,
                Key.CalibrateLeft,
                Key.CalibrateRight,
                Key.CalibrateUp,
                Key.CalibrateDown,
            };

            if (is_repetition && !repetition_white_list.Contains(key))
            {
                return(true);
            }

            if (key_state == KeyState.Down)
            {
                // Calibration
                int calibration_step = (int)(Options.Instance.calibration_step * speed_up);
                if (key == Key.CalibrateLeft)
                {
                    StartCalibration();
                    smoothened_error_correction.shift.X -= calibration_step;
                }
                if (key == Key.CalibrateRight)
                {
                    StartCalibration();
                    smoothened_error_correction.shift.X += calibration_step;
                }
                if (key == Key.CalibrateUp)
                {
                    StartCalibration();
                    smoothened_error_correction.shift.Y -= calibration_step;
                }
                if (key == Key.CalibrateDown)
                {
                    StartCalibration();
                    smoothened_error_correction.shift.Y += calibration_step;
                }

                // Scroll
                if (key == Key.ScrollDown)
                {
                    MouseButtons.WheelDown((int)(Options.Instance.vertical_scroll_step * speed_up));
                }
                if (key == Key.ScrollUp)
                {
                    MouseButtons.WheelUp((int)(Options.Instance.vertical_scroll_step * speed_up));
                }
                if (key == Key.ScrollLeft)
                {
                    MouseButtons.WheelLeft((int)(Options.Instance.horizontal_scroll_step * speed_up));
                }
                if (key == Key.ScrollRight)
                {
                    MouseButtons.WheelRight((int)(Options.Instance.horizontal_scroll_step * speed_up));
                }
            }

            // Mouse buttons
            if (mouse_state == MouseState.Calibrating &&
                (key == Key.LeftMouseButton || key == Key.RightMouseButton))
            {
                CalibrationManager.Instance.AddShift(smoothened_error_correction.сoordinates, smoothened_error_correction.shift);
                mouse_state = MouseState.Controlling;
            }

            if (key == Key.LeftMouseButton)
            {
                if (key_state == KeyState.Down)
                {
                    // Freeze cursor for a short period of time after mouse clicks to make double clicks esier.
                    MouseButtons.LeftDown();
                    freeze_until = DateTime.Now.AddMilliseconds(Options.Instance.click_freeze_time_ms);
                    statistics.OnClick();
                }
                else if (key_state == KeyState.Up)
                {
                    MouseButtons.LeftUp();
                }
            }

            if (key == Key.RightMouseButton)
            {
                if (key_state == KeyState.Down)
                {
                    // Freeze cursor for a short period of time after mouse clicks to make double clicks esier.
                    MouseButtons.RightDown();
                    freeze_until = DateTime.Now.AddMilliseconds(Options.Instance.click_freeze_time_ms);
                    statistics.OnClick();
                }
                else if (key_state == KeyState.Up)
                {
                    MouseButtons.RightUp();
                }
            }

            if (key == Key.ShowCalibrationView && key_state == KeyState.Down)
            {
                CalibrationManager.Instance.IsDebugWindowEnabled = !CalibrationManager.Instance.IsDebugWindowEnabled;
            }

            return(true);
        }
Esempio n. 5
0
 public void RightUp()
 {
     MouseButtons.RightUp();
 }