Ejemplo n.º 1
0
 /// <summary>
 /// Background thread runs this function in a loop reading SpacePilot state.
 /// </summary>
 void SpacePilotLoop()
 {
     while (true)
     {
         Thread.Sleep(20);
         try
         {
             // Poll the device for info.
             spacePilot.Poll();
             HandleSpacePilot();
         }
         catch (InputException inputex)
         {
             if ((inputex is NotAcquiredException) || (inputex is InputLostException))
             {
                 // Check to see if either the app
                 // needs to acquire the device, or
                 // if the app lost the device to another
                 // process.
                 try
                 {
                     // Acquire the device.
                     spacePilot.Acquire();
                 }
                 catch (InputException)
                 {
                     // Failed to acquire the device.
                     // This could be because the app
                     // doesn't have focus.
                     Thread.Sleep(1000);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void Update()
        {
            if (!isInitialized || joystick == null)
            {
                return;
            }

            try {
                joystick.Poll();
                state = joystick.CurrentJoystickState;
            }
            catch (Microsoft.DirectX.DirectInput.InputException de) {
                System.Windows.Forms.MessageBox.Show("The connection to the joystick has been lost.", "Joystick Problem", System.Windows.Forms.MessageBoxButtons.OK);
                isInitialized = false;
            }
        }
Ejemplo n.º 3
0
        private void timerPoll_Tick(object sender, EventArgs e)
        {
            try
            {
                deviceInput.Poll();
                deviceInputState = deviceInput.CurrentJoystickState;
            }
            catch (NotAcquiredException)
            {
                // try to reqcquire the device
                try { deviceInput.Acquire(); }
                catch (InputException iex) { Console.WriteLine(iex.Message); }
            }
            catch (InputException ex2) { Console.WriteLine(ex2.Message); }

            this.currentJoystickSmoothness = ((deviceInputState.Y / ((double)65536))) * 20 + 1;
            this.currentJoystickWidth      = (deviceInputState.X * 2 / ((double)65536) - 1.0) * 0.7;
        }
Ejemplo n.º 4
0
        public void Update()
        {
            if (!isInitialized || joystick == null)
            {
                return;
            }

            //Prevent windows going to sleep. Certain input devices don't seem to hint windows to prevent suspend mode, apparently.
            NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED);
            try {
                joystick.Poll();
                state = joystick.CurrentJoystickState;
            }
            catch (Microsoft.DirectX.DirectInput.InputException de) {
                System.Windows.Forms.MessageBox.Show("The connection to the joystick has been lost.", "Joystick Problem", System.Windows.Forms.MessageBoxButtons.OK);
                isInitialized = false;
            }
        }
Ejemplo n.º 5
0
        private void UpdateKeyboard()
        {
            //Capture pressed keys.
            Key[] keys = null;
            try
            {
                keyboard.Poll();
                keys = keyboard.GetPressedKeys();
            }
            catch (InputLostException)
            {
                try
                {
                    FreeDirectInput();
                    InitInputDevices();
                    keys = keyboard.GetPressedKeys();
                }
                catch (InputException ex)
                {
                    Logging.Logger.AddError("CHYBA - V INPUTU " + ex.ToString());
                    return;
                }
            }
            foreach (Key k in keys)
            {
                switch (k)
                {
                case Key.W:
                    actions.Add(Action.MoveForwardStart);
                    break;

                case Key.S:
                    actions.Add(Action.MoveBackwardStart);
                    break;

                case Key.A:
                    actions.Add(Action.MoveLeftStart);
                    break;

                case Key.D:
                    actions.Add(Action.MoveRightStart);
                    break;

                case Key.Escape:
                    actions.Add(Action.Exit);
                    break;

                case Key.U:
                    actions.Add(Action.InvertMouse);
                    break;

                case Key.F:
                    actions.Add(Action.Action3);
                    break;

                case Key.Return:
                    actions.Add(Action.ChangeFillMode);
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void UpdateMouse()
        {
            MouseState mouseState;

            try
            {
                mouse.Poll();
                mouseState = mouse.CurrentMouseState;
            }
            catch (Microsoft.DirectX.DirectInput.InputLostException)
            {
                try
                {
                    FreeDirectInput();
                    InitInputDevices();
                    mouseState = mouse.CurrentMouseState;
                }
                catch (Microsoft.DirectX.DirectInput.InputException ex)
                {
                    Logging.Logger.AddWarning("CHYBA - V INPUTU " + ex.ToString());
                    return;
                }
            }

            this.mouseRelativeMove.X = mouseState.X;
            this.mouseRelativeMove.Y = mouseState.Y;
            this.iMouseWheel         = mouseState.Z;

            this.mouseLocation.X += (int)mouseRelativeMove.X;
            this.mouseLocation.Y += (int)mouseRelativeMove.Y;

            if (this.mouseLocation.X < 0)
            {
                this.mouseLocation.X = 0;
            }
            else if (this.mouseLocation.X > this.windowControl.Size.Width - 1)
            {
                this.mouseLocation.X = this.windowControl.Size.Width - 1;
            }
            if (this.mouseLocation.Y < 0)
            {
                this.mouseLocation.Y = 0;
            }
            else if (this.mouseLocation.Y > this.windowControl.Size.Height - 1)
            {
                this.mouseLocation.Y = this.windowControl.Size.Height - 1;
            }

            if (this.iMouseWheel > 0)
            {
                actions.Add(Action.Wheel);
            }
            ;
            if (this.mouseRelativeMove.X != 0 || this.mouseRelativeMove.Y != 0)
            {
                this.actions.Add(Action.LookAround);
                //Logging.Logger.AddInfo("Udalost mysi");
            }

            byte[] buttons = mouseState.GetMouseButtons();
            for (int i = 0; i < buttons.Length; i++)
            {
                if (buttons[i] != 0)
                {
                    switch (i)
                    {
                    case 0:
                        actions.Add(Action.Action1);
                        break;

                    case 1:
                        actions.Add(Action.Action2);
                        break;

                    case 2:
                        actions.Add(Action.Action3);
                        break;
                    }
                }
            }
        }