当前位置: 首页>>代码示例>>C#>>正文


C# JoystickState.GetButtons方法代码示例

本文整理汇总了C#中JoystickState.GetButtons方法的典型用法代码示例。如果您正苦于以下问题:C# JoystickState.GetButtons方法的具体用法?C# JoystickState.GetButtons怎么用?C# JoystickState.GetButtons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JoystickState的用法示例。


在下文中一共展示了JoystickState.GetButtons方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessController

        protected override void ProcessController()
        {
            ControllerState newState = new ControllerState();
            JoystickState joyState = new JoystickState();

            if (this.padsList == null || !this.padsList.Any())
            {
                this.padsList = this.GetGamePads();
                if (!this.padsList.Any()) return;
            }

            if (this.device == null)
            {
                this.device = this.padsList[0];
            }

            if (this.pad == null)
            {
                this.Acquire();
            }

            if (this.pad == null || this.pad.Poll().IsFailure || this.pad.GetCurrentState(ref joyState).IsFailure)
            {
                newState.Active = false;
            }
            else
            {
                //var objs = pad.GetObjects();
                newState.Active = true;
                newState.X = (joyState.X / 5000d);
                newState.Y = (joyState.Y / 5000d);
                newState.Buttons = joyState.GetButtons();
            }

            if (!newState.Equals(this.State))
            {

                this.State = newState;

                if (this.OnUpdate != null)
                {
                    this.OnUpdate.Invoke(this.State);
                }
            }
        }
开发者ID:jochym,项目名称:ASCOM-Celestron-Telescope-Driver-RS232-BT,代码行数:45,代码来源:GamePad.cs

示例2: PollChanges

        public void PollChanges(iGameClient GameCli)
        {
            //polls changes in this controller from the previous poll and raises
            //appropriate events in iGameClient depending on the differences.
            if (!haspolled)
            {
                haspolled=true;
                ourdevice.Poll();
                laststate = ourdevice.CurrentJoystickState;
                return;

            }
            laststate = ourdevice.CurrentJoystickState;
            ourdevice.Poll();

            byte[] prevbuttons = laststate.GetButtons();
            byte[] currbuttons = ourdevice.CurrentJoystickState.GetButtons();
        }
开发者ID:BCProgramming,项目名称:BASeBlock,代码行数:18,代码来源:gamepadinput.cs

示例3: GetButtons

        public List<int> GetButtons()
        {
            if (Pad.Acquire().IsFailure)
                return null;

            if (Pad.Poll().IsFailure)
                return null;

            State = Pad.GetCurrentState();
            if (Result.Last.IsFailure)
                return null;

            var answer = new List<int>();

            bool[] buttons = State.GetButtons();
            for (int b = 0; b < buttons.Length; b++)
            {
                if (buttons[b])
                    answer.Add(b);
            }
            return answer;
        }
开发者ID:tobig82,项目名称:iRduino,代码行数:22,代码来源:ControllerDevice.cs

示例4: CheckInput

        private bool CheckInput(JoystickState state, int index)
        {
            if (state == null)
                return false;

            var buttons = state.GetButtons();
            for (var button = 0; button < buttons.Length; button++)
            {
                if (buttons[button])
                {
                    _inputName = "Joystick" + index + "." + button;
                    return true;
                }

                if (state.X > 0xC000)
                {
                    _inputName = "Joystick" + index + ".X+";
                    return true;
                }
                else if (state.X < 0x4000)
                {
                    _inputName = "Joystick" + index + ".X-";
                    return true;
                }
                else if (state.Y > 0xC000)
                {
                    _inputName = "Joystick" + index + ".Y+";
                    return true;
                }
                else if (state.Y < 0x4000)
                {
                    _inputName = "Joystick" + index + ".Y-";
                    return true;
                }
            }
            return false;
        }
开发者ID:afonsof,项目名称:nes-hd,代码行数:37,代码来源:Frm_Key.cs

示例5: StickHandlingLogic

        void StickHandlingLogic(Joystick stick, int id)
        {
            //Console.WriteLine("here2");
            // Creates an object from the class JoystickState.
            JoystickState state = new JoystickState();

            state = stick.GetCurrentState(); //Gets the state of the joystick
            //Console.WriteLine(state);
            //These are for the thumbstick readings
            yValue = -state.Y;
            xValue = state.X;
            zValue = state.Z;
            rotationZValue = state.RotationZ;
            rotationXValue = state.RotationY;
            rotationYValue = state.RotationX;

            int th = 0;
            int[] z = state.GetSliders();
            th= z[0];
            if (z[0] == 0 && isFirst)
            {
                th = 0;

            }
            else
            {
                if(isFirst) isFirst = false;
                if (th >= 0)
                {
                    th = 50 - th / 2;
                }
                else
                {
                    th = -th / 2 + 50;
                }
            }

            Console.Write("thrust = " + th);

            Console.WriteLine(" x = " + xValue + " y = " + yValue + " z = " + zValue + " rot x = " + rotationXValue + " rot y = " + rotationYValue + " rot Z = " + rotationZValue);

            bool[] buttons = state.GetButtons(); // Stores the number of each button on the gamepad into the bool[] butons.
               // Console.WriteLine("# of button = " + buttons.Length);
            //Here is an example on how to use this for the joystick in the first index of the array list
            if (id == 0)
            {
                // This is when button 0 of the gamepad is pressed, the label will change. Button 0 should be the square button.
                if (buttons[0])
                {

                }

            }
        }
开发者ID:ElliotHYLee,项目名称:JoyStick,代码行数:54,代码来源:Form1.cs

示例6: Update

        public override void Update(TimeSpan elapsedTime)
        {
            buttonDown = -1;

            if (getInputData)
                getInputData = false;
            else
                return;

            if (joystick != null)
            {
                if (joystick.Acquire().IsFailure ||
                    joystick.Poll().IsFailure)
                    return;

                state = joystick.GetCurrentState();

                if (Result.Last.IsFailure)
                    return;

                joystickIsReady = true;

                bool[] buttons = state.GetButtons();

                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        buttonDown = i;
                        break;
                    }
                }
            }
        }
开发者ID:zulis,项目名称:Cubica,代码行数:34,代码来源:JoyStick.cs

示例7: CheckJoystickInput

        private bool CheckJoystickInput()
        {
            if (joystick.Acquire().IsSuccess)
            {
                joystickState = joystick.GetCurrentState();
                if (joystickState == null)
                    return false;

                bool[] buttons = joystickState.GetButtons();
                for (int button = 0; button < buttons.Length; button++)
                {
                    if (buttons[button])
                    {
                        _inputName = button.ToString();
                        return true;
                    }

                    if (joystickState.X > 0xC000)
                    {
                        _inputName = "X+";
                        return true;
                    }
                    else if (joystickState.X < 0x4000)
                    {
                        _inputName = "X-";
                        return true;
                    }
                    else if (joystickState.Y > 0xC000)
                    {
                        _inputName = "Y+";
                        return true;
                    }
                    else if (joystickState.Y < 0x4000)
                    {
                        _inputName = "Y-";
                        return true;
                    }
                }
            }
            return false;
        }
开发者ID:ywjno,项目名称:mynes-code,代码行数:41,代码来源:FormKey.cs

示例8: ReadPaddle

		public void ReadPaddle()
		{
			paddleDevice.Poll();
			jsState = paddleDevice.CurrentJoystickState;
			byte[] contacts = jsState.GetButtons();
			int thisDit = contacts[0];
			int thisDah = contacts[1];
			if(thisDit != lastDit | (thisDah != lastDah))
			{
				lastDit = thisDit;
				lastDah = thisDah;
				int[] bauds = {thisDit, thisDah};
				OnChanged(bauds);
			}			
		}
开发者ID:HosokawaKenchi,项目名称:powersdr-if-stage,代码行数:15,代码来源:paddle.cs

示例9: update

        //end of WTF

        //Updating values from joystick
        public void update()
        {
            Joystick stick = sticks[0];
            state = stick.GetCurrentState();

            for (int i = 0; i < 1; i++) //i indicating which joystick to update
            {
                //Update axes values
                axis[0] = state.AccelerationX; //Ax
                axis[1] = state.AccelerationY; //Ay
                axis[2] = state.AccelerationZ; //Az
                axis[3] = state.AngularAccelerationX; //aAx
                axis[4] = state.AngularAccelerationY; //aAy
                axis[5] = state.AngularAccelerationZ; //aAz
                axis[6] = state.AngularVelocityX; //aVx
                axis[7] = state.AngularVelocityY; //aVy
                axis[8] = state.AngularVelocityZ; //aVz
                axis[9] = state.ForceX; //Fx
                axis[10] = state.ForceY; //Fy
                axis[11] = state.ForceZ; //Fz
                axis[12] = state.RotationX; //Rx
                axis[13] = state.RotationY; //Ry
                axis[14] = state.RotationZ; //Rz
                axis[15] = state.TorqueX; //Tx
                axis[16] = state.TorqueY; //Ty
                axis[17] = state.TorqueZ; //Tz
                axis[18] = state.VelocityX; //Vx
                axis[19] = state.VelocityY; //Vy
                axis[20] = state.VelocityZ; //Vz
                axis[21] = state.X; //x
                axis[22] = state.Y; //y
                axis[23] = state.Z; //z

                //Update button values
                buttons[i] = state.GetButtons();

            }

        }
开发者ID:rtorsvik,项目名称:ROVInterface,代码行数:42,代码来源:JoystickHandeler.cs

示例10: GamePadState


//.........这里部分代码省略.........
        {
          this.AngularAccelerationZ = 0.0f;
        }

        if (axisReaders[21] != null)
        {
          this.TorqueX = axisReaders[21].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueX = 0.0f;
        }
        if (axisReaders[22] != null)
        {
          this.TorqueY = -axisReaders[22].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueY = 0.0f;
        }
        if (axisReaders[23] != null)
        {
          this.TorqueZ = axisReaders[23].GetValue(ref joystickState);
        }
        else
        {
          this.TorqueZ = 0.0f;
        }
      }

      // Take over the joystick's buttons
      {
        this.ButtonCount = converter.ButtonCount;
        bool[] buttonPressed = joystickState.GetButtons();

        this.buttonState1 = 0;
        for (int index = 0; index < Math.Min(64, ButtonCount); ++index)
        {
          if (buttonPressed[index])
          {
            this.buttonState1 |= (1UL << index);
          }
        }

        this.buttonState2 = 0;
        for (int index = 0; index < (ButtonCount - 64); ++index)
        {
          if (buttonPressed[index + 64])
          {
            this.buttonState2 |= (1UL << index);
          }
        }
      }

      // Take over the joystick's sliders
      {
        this.AvailableSliders = converter.AvailableSliders;
        DirectInputConverter.ISliderReader[] sliderReaders = converter.SliderReaders;

        if (sliderReaders[0] != null)
        {
          this.Slider1 = sliderReaders[0].GetValue(ref joystickState);
        }
        else
        {
          this.Slider1 = 0.0f;
开发者ID:Azzuro,项目名称:IR-Server-Suite,代码行数:67,代码来源:GamePadState.Builders.cs

示例11: UpdateJoystick

        public static void UpdateJoystick(int joystick, ref string pressedButton)
        {
            try
            {
                pressedButton = "";
                state = joysticks[joystick].CurrentJoystickState;
                buttons = state.GetButtons(); // Capture buttons state.

                for (int i = 0; i < buttonPressed[joystick].Length; i++)
                {
                    if (buttons[i] != 0)
                    {
                        if (buttonPressed[joystick][i] == false)
                        {
                            pressedButton += "Btn" + i + ":";
                            buttonPressed[joystick][i] = true;
                        }
                    }
                    else
                        buttonPressed[joystick][i] = false; // release button
                }
            }
            catch (Exception e)
            {
                ImportExport.LogMessage("UpdateJoystick ... " + e.ToString(), true);
            }
        }
开发者ID:H-J-P,项目名称:DAC-Source,代码行数:27,代码来源:Joystick.cs

示例12: ReactToDigitalEvents

 private bool ReactToDigitalEvents(List<ButtonMapping> mappingsForDevice, JoystickState state)
 {
     byte[] buttonStates = state.GetButtons();
     bool atLeastOneChange = false;
     for (int i = 0; i < mappingsForDevice.Count; i++)
     {
         byte bs = buttonStates[i];
         if (bs >= 128)
         {
             if (!mappingsForDevice[i].Pressed)
             {
                 mappingsForDevice[i].Pressed = true;
                 atLeastOneChange = true;
                 // TODO: carry out configured _pressed_ action, if appropriate
             }
         }
         else
         {
             if (mappingsForDevice[i].Pressed)
             {
                 mappingsForDevice[i].Pressed = false;
                 atLeastOneChange = true;
                 // TODO: carry out configured _release_ action, if appropriate
             }
         }
     }
     return atLeastOneChange;
 }
开发者ID:olivierdagenais,项目名称:yeehawklipklippe,代码行数:28,代码来源:ElectricSunlightOrchestra.cs

示例13: procesar

        private void procesar(Joystick stick)
        {
            try
            {
                JoystickState state = new JoystickState();
                state = stick.GetCurrentState();

                string nombre = stick.Information.InstanceName; //instance name
                lblNombre.Text = nombre;

                bool[] botones = state.GetButtons();
                if (botones.Length >= 10)
                {
                    if (botones[0] == true)
                    {
                        boton0.Image = muestraActivado.Image;
                    }
                    if (botones[1] == true)
                    {
                        boton1.Image = muestraActivado.Image;
                    }
                    if (botones[2] == true)
                    {
                        boton2.Image = muestraActivado.Image;
                    }
                    if (botones[3] == true)
                    {
                        boton3.Image = muestraActivado.Image;
                    }
                    if (botones[4] == true)
                    {
                        boton4.Image = muestraActivado.Image;
                    }
                    if (botones[5] == true)
                    {
                        boton5.Image = muestraActivado.Image;
                    }
                    if (botones[6] == true)
                    {
                        boton6.Image = muestraActivado.Image;
                    }
                    if (botones[7] == true)
                    {
                        boton7.Image = muestraActivado.Image;
                    }
                    if (botones[8] == true)
                    {
                        boton8.Image = muestraActivado.Image;
                    }
                    if (botones[9] == true)
                    {
                        boton9.Image = muestraActivado.Image;
                    }
                    int sx = state.X;
                    int sy = state.Y;
                    if (sx == -1000)
                    {
                        boton13.Image = muestraActivado.Image;
                    }
                    else if (sx == 1000)
                    {
                        boton11.Image = muestraActivado.Image;
                    }
                    if (sy == -1000)
                    {
                        boton10.Image = muestraActivado.Image;
                    }
                    else if (sy == 1000)
                    {
                        boton12.Image = muestraActivado.Image;
                    }
                }
                else
                {
                    MessageBox.Show("El dispositivo no es del tipo adecuado o está dañado.", "Dispositivo incorrecto", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            { 
            }
        }
开发者ID:ludwingperezt,项目名称:AsocTKDXela,代码行数:81,代码来源:Dispositivos.cs

示例14: ComputeInputs

        private void ComputeInputs()
        {
            // Pull from joystick
            if (joystick != null)
            {
                joystick.Poll();
                state = joystick.GetCurrentState();
                pov_state = (POV_HAT_DIR)state.GetPointOfViewControllers()[0];
                button_state = state.GetButtons();
                control_x = state.X;
                control_y = state.Y;
                control_z = state.RotationZ;
                control_throttle = state.GetSliders()[0];
                if (control_x > 0 && control_x < JOYSTICK_XY_DEADBAND) { control_x = 0; }
                if (control_x < 0 && control_x > -JOYSTICK_XY_DEADBAND) { control_x = 0; }
                if (control_y > 0 && control_y < JOYSTICK_XY_DEADBAND) { control_y = 0; }
                if (control_y < 0 && control_y > -JOYSTICK_XY_DEADBAND) { control_y = 0; }
                if (control_z > 0 && control_z < JOYSTICK_Z_DEADBAND) { control_z = 0; }
                if (control_z < 0 && control_z > -JOYSTICK_Z_DEADBAND) { control_z = 0; }
            }
            else
            {
                state = new JoystickState();
                button_state = new bool[] { false, false, false, false };
                control_x = 0;
                control_y = 0;
                pov_state = POV_HAT_DIR.NONE;
            }

            // Turret
            switch (pov_state)
            {
                case POV_HAT_DIR.NW:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = true;// left
                    break;
                case POV_HAT_DIR.N:
                    turret_vert_pwr = TURRET_VERT_SPEED_MED;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = 0;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.NE:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.E:
                    turret_vert_pwr = 0;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_MED;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.SE:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.S:
                    turret_vert_pwr = TURRET_VERT_SPEED_MED;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = 0;
                    turret_horiz_fwd = false;// right
                    break;
                case POV_HAT_DIR.SW:
                    turret_vert_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_vert_fwd = false;// up
                    turret_horiz_pwr = TURRET_VERT_SPEED_SLOW;
                    turret_horiz_fwd = true;// left
                    break;
                case POV_HAT_DIR.W:
                    turret_vert_pwr = 0;
                    turret_vert_fwd = true;// down
                    turret_horiz_pwr = TURRET_VERT_SPEED_MED;
                    turret_horiz_fwd = true;// left
                    break;

                default:
                    turret_vert_pwr = 0;
                    turret_horiz_pwr = 0;
                    break;
            }

            // Normal weapons
            /*if (button_state[0])
            {
                weapon1_fwd = true;
                weapon1_pwr = 255;
            }
            else
            {
                weapon1_fwd = true;
                weapon1_pwr = 0;
            }
            if (button_state[1])
            {
//.........这里部分代码省略.........
开发者ID:jwalthour,项目名称:wamp,代码行数:101,代码来源:MainWindow.xaml.cs

示例15: SendActions

    private void SendActions(JoystickState state)
    {
      int actionCode = -1;
      int actionParam = -1;
      int curAxisValue = 0;
      // todo: timer stuff!!

      // buttons first!
      byte[] buttons = state.GetButtons();
      int button = 0;
      string pressedButtons = "";

      // button combos
      string sep = "";
      foreach (byte b in buttons)
      {
        if (0 != (b & 0x80))
        {
          pressedButtons += sep + button.ToString("00");
          sep = ",";
        }
        button++;
      }

      if ((ButtonComboKill != "") && (ButtonComboKill == pressedButtons))
      {
        if (null != _lastProc)
        {
          actionCode = (int)joyButton.comboKillProcess;
          actionParam = _lastProc.Id;
        }
      }
      else if ((ButtonComboClose != "") && (ButtonComboClose == pressedButtons))
      {
        if (null != _lastProc)
        {
          actionCode = (int)joyButton.comboCloseProcess;
          actionParam = _lastProc.Id;
        }
      }

      // single buttons
      if (actionCode == -1)
      {
        button = 0;
        bool foundButton = false;
        foreach (byte b in buttons)
        {
          if (0 != (b & 0x80))
          {
            foundButton = true;
            break;
          }
          button++;
        }
        if (foundButton)
        {
          if ((button >= 0) && (button <= 19))
          {
            // don't need no stinkin' enum-constants here....
            actionCode = 3030 + button;
          }
        }
      }

      // pov next
      if (actionCode == -1)
      {
        int[] pov = state.GetPointOfView();
        switch (pov[0])
        {
          case 0:
            {
              actionCode = (int)joyButton.povN;
              break;
            }
          case 9000:
            {
              actionCode = (int)joyButton.povE;
              break;
            }
          case 18000:
            {
              actionCode = (int)joyButton.povS;
              break;
            }
          case 27000:
            {
              actionCode = (int)joyButton.povW;
              break;
            }
        }
      }

      if (actionCode == -1)
      {
        // axes next
        if (Math.Abs(state.X) > _axisLimit)
        {
          curAxisValue = state.X;
//.........这里部分代码省略.........
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:101,代码来源:DirectInputHandler.cs


注:本文中的JoystickState.GetButtons方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。