private void SwitchKeyEvent(bool KeyDown, KeyEventArgs e)
        {
            if (client == null)
            {
                return;
            }
            int defaultDistance   = 35;
            int defaultTurnDegree = 20;

            bool flipFunctionKeyDown  = Keyboard.IsKeyDown(Key.LeftCtrl);
            bool speedFunctionKeyDown = Keyboard.IsKeyDown(Key.LeftShift);


            if (joystickMode && !joystickDataSender.IsEnabled && e.Key == Key.Up && !flipFunctionKeyDown)
            {
                joystickDataSender.Start();
            }

            FlipShift(flipFunctionKeyDown);
            SpeedShift(speedFunctionKeyDown);

            if (KeyDown && e.Key != Key.Escape)
            {
                escapeTimes = 0;
                emergency_notification.Visibility = Visibility.Collapsed;
            }

            try
            {
                switch (e.Key)
                {
                case Key.W: HandleKeyEvent(KeyDown, img_forward_gray); if (KeyDown && !joystickMode)
                    {
                        client.Forward(defaultDistance);
                    }
                    break;

                case Key.S: HandleKeyEvent(KeyDown, img_backward_gray); if (KeyDown && !joystickMode)
                    {
                        client.Backward(defaultDistance);
                    }
                    break;

                case Key.A: HandleKeyEvent(KeyDown, img_left_gray); if (KeyDown && !joystickMode)
                    {
                        client.Left(defaultDistance);
                    }
                    break;

                case Key.D: HandleKeyEvent(KeyDown, img_right_gray); if (KeyDown && !joystickMode)
                    {
                        client.Right(defaultDistance);
                    }
                    break;

                case Key.Up:
                    HandleKeyEvent(KeyDown, img_up_gray, flipFunctionKeyDown, img_flip_forward);
                    if (KeyDown && !joystickMode && !flipFunctionKeyDown)
                    {
                        client.Up(defaultDistance);
                    }
                    if (KeyDown && flipFunctionKeyDown)
                    {
                        client.Flip(FlipDirection.FORWARD);
                    }
                    break;

                case Key.Down:
                    HandleKeyEvent(KeyDown, img_down_gray, flipFunctionKeyDown, img_flip_backward);
                    if (KeyDown && !joystickMode && !flipFunctionKeyDown)
                    {
                        client.Down(defaultDistance);
                    }
                    if (KeyDown && flipFunctionKeyDown)
                    {
                        client.Flip(FlipDirection.BACKWARD);
                    }
                    break;

                case Key.Left:
                    HandleKeyEvent(KeyDown, img_ccw_gray, flipFunctionKeyDown, img_flip_left);
                    if (KeyDown && !joystickMode && !flipFunctionKeyDown)
                    {
                        client.TurnLeft(defaultTurnDegree);
                    }
                    if (KeyDown && flipFunctionKeyDown)
                    {
                        client.Flip(FlipDirection.LEFT);
                    }
                    break;

                case Key.Right:
                    HandleKeyEvent(KeyDown, img_cw_gray, flipFunctionKeyDown, img_flip_right);
                    if (KeyDown && !joystickMode && !flipFunctionKeyDown)
                    {
                        client.TurnRight(defaultTurnDegree);
                    }
                    if (KeyDown && flipFunctionKeyDown)
                    {
                        client.Flip(FlipDirection.RIGHT);
                    }
                    break;

                case Key.Space: HandleKeyEvent(KeyDown, img_land_gray); if (KeyDown)
                    {
                        client.Land();
                    }
                    joystickDataSender.Stop(); break;

                case Key.Escape: HandleKeyEvent(KeyDown, img_emergency_gray); if (KeyDown)
                    {
                        HandleEmergency();
                    }
                    break;

                case Key.Enter: HandleKeyEvent(KeyDown, img_takeoff_gray); if (KeyDown)
                    {
                        client.TakeOff();
                    }
                    break;

                case Key.R: HandleKeyEvent(KeyDown, img_start_rotors_gray); if (KeyDown)
                    {
                        client.StartRotors();
                    }
                    break;

                case Key.Q: HandleKeyEvent(KeyDown, img_dec_speed_gray); if (KeyDown)
                    {
                        client.DecreaseSpeed();
                    }
                    break;

                case Key.E: HandleKeyEvent(KeyDown, img_inc_speed_gray); if (KeyDown)
                    {
                        client.IncreaseSpeed();
                    }
                    break;

                case Key.P: SwitchStream(KeyDown); break;
                }
            }
            catch (CommandIntegerParamException ie)
            {
                txt_response.Text       = ie.Message;
                txt_response.Background = red;
            }
            catch (CommandStringParamException se)
            {
                txt_response.Text       = se.Message;
                txt_response.Background = red;
            }
            catch (DroneCurveException ce)
            {
                txt_response.Text       = ce.Message;
                txt_response.Background = red;
            }
            txt_current_speed.Content = client.CurrentSpeed;
        }