Exemplo n.º 1
0
 public void Release()
 {
     if (_device != null && IsAcquired)
     {
         lock (_device) {
             _device.Unacquire();
             IsAcquired = false;
             _waitHandle.Set();
         }
     }
 }
Exemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            stopThread = true;

            if (poolingThread != null)
            {
                poolingThread.Abort();
            }

            gamepad.Unacquire();

            base.Dispose(disposing);
        }
Exemplo n.º 3
0
        private void CaptureThread()
        {
            while (true)
            {
                try
                {
                    if (!this.isCapturing)
                    {
                        return;
                    }

                    if (gamepad.Acquire().IsFailure)
                    {
                        return;
                    }

                    if (gamepad.Poll().IsFailure)
                    {
                        return;
                    }

                    if (SlimDX.Result.Last.IsFailure)
                    {
                        return;
                    }

                    state = gamepad.GetCurrentState();

                    bool[] buttons = state.GetButtons();
                    //for (int i = 0; i < buttons.Length; i++)
                    //    if (buttons[i])
                    //        label2.Text = i.ToString();
                }
                catch (Exception ex) { }


                if (OnStateUpdated != null)
                {
                    OnStateUpdated(state);
                }

                try
                {
                    gamepad.Unacquire();
                }
                catch (Exception ex) { }

                Thread.Sleep(50);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Отключение
 /// </summary>
 public void Disconnect()
 {
     try
     {
         lock (_threadLock)
         {
             _quitThread = true;
         }
         _joystickThread.Join();
         _joystick.Unacquire();
         _joystick.Dispose();
         _directInput.Dispose();
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 5
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            for (int i = 0; i < reverserSwitchKeyTexts.Length; i++)
            {
                addKey(reverserSwitchKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    0, i
                });
            }
            for (int i = 0; i < cabSwitchKeyTexts.Length; i++)
            {
                addKey(cabSwitchKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -1, i
                });
            }
            for (int i = 0; i < atsKeyTexts.Length; i++)
            {
                addKey(atsKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -2, i
                });
            }
            for (int i = 0; i < gameControlKeyTexts.Length; i++)
            {
                addKey(gameControlKeyTexts[i]);
                keyCodeTable.Add(new int[2] {
                    -3, i
                });
            }

            selectDropDownList(buttonSKeyList, DenshadeGoInterface.settings.ButtonS);
            selectDropDownList(buttonPKeyList, DenshadeGoInterface.settings.ButtonP);
            selectDropDownList(buttonAKeyList, DenshadeGoInterface.settings.ButtonA);
            selectDropDownList(buttonBKeyList, DenshadeGoInterface.settings.ButtonB);
            selectDropDownList(buttonCKeyList, DenshadeGoInterface.settings.ButtonC);

            bool added = false;
            List <SlimDX.DirectInput.Joystick> sticks = new List <SlimDX.DirectInput.Joystick>();

            foreach (DeviceInstance device in DenshadeGoInterface.input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    controllerList.Items.Add(device.ProductName);
                    Joystick stick = new SlimDX.DirectInput.Joystick(DenshadeGoInterface.input, device.InstanceGuid);
                    stick.Acquire();
                    int size = stick.GetCurrentState().GetButtons().Length;
                    buttonSize.Add(size);
                    if (device.ProductName.Equals(DenshadeGoInterface.settings.ControllerName))
                    {
                        added = true;
                        controllerList.SelectedIndex = controllerList.Items.Count - 1;
                        resizeUpDown(size);
                    }
                    stick.Unacquire();
                }
                catch (DirectInputException)
                {
                }
            }
            if (!added)
            {
                buttonSize.Add(128);
                controllerList.Items.Add(DenshadeGoInterface.settings.ControllerName);
                controllerList.SelectedIndex = controllerList.Items.Count - 1;
                resizeUpDown(128);
            }
            loadUpDown();
        }