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


C# Joystick.GetCurrentState方法代码示例

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


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

示例1: InitializeController

 public void InitializeController(Guid initGuid)
 {
     controllerGuid = Guid.Empty;
     var deviceInst = input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly);
     if (deviceInst.Count == 0)
     {
         deviceInst = input.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly);
     }
     if (deviceInst.Count > 0)
     {
         foreach (var device in deviceInst)
         {
             if (device.InstanceGuid == initGuid)
             {
                 controllerGuid = initGuid;
             }
         }
         if (controllerGuid == Guid.Empty)
         {
             controllerGuid = deviceInst[0].InstanceGuid;
         }
         controller = new Joystick(input, controllerGuid);
         controller.Acquire();
         defaultControllerState = controller.GetCurrentState();
     }
 }
开发者ID:Silenthal,项目名称:gbemu,代码行数:26,代码来源:Win32InputHandler.cs

示例2: getFirstPressedButton

        public void getFirstPressedButton()
        {
            while (listening)
            {
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Driving,
                DeviceEnumerationFlags.AllDevices))
                {
                    Guid joystickGuid = deviceInstance.InstanceGuid;
                    if (joystickGuid == Guid.Empty)
                    {
                        listening = false;
                    }
                    else
                    {
                        // Instantiate the joystick
                        var joystick = new Joystick(directInput, joystickGuid);

                        Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                        // Acquire the joystick
                        joystick.Acquire();
                        JoystickState state = joystick.GetCurrentState();
                        Boolean[] buttons = state.Buttons;
                        Boolean useThisJoystick = false;
                        for (int i = 0; i < buttons.Count(); i++)
                        {
                            if (buttons[i])
                            {
                                this.joystickToUse = joystick;
                                this.buttonIndex = i;
                                Console.WriteLine("Using button index " + buttonIndex + " for device guid " + joystickGuid);
                                listening = false;
                                useThisJoystick = true;
                                break;
                            }
                        }
                        if (!useThisJoystick)
                        {
                            joystick.Unacquire();
                        }
                    }
                }
                Thread.Sleep(1000);
            }
            Console.WriteLine("Got button " + buttonIndex);
        }
开发者ID:mrbelowski,项目名称:r3e_crewchief,代码行数:46,代码来源:ButtonRequest.cs

示例3: UpdateFrom

 public void UpdateFrom(Joystick device, out JoystickState state)
 {
     if (!AppHelper.IsSameDevice(device, deviceInstanceGuid))
     {
         ShowDeviceInfo(device);
         deviceInstanceGuid = Guid.Empty;
         if (device != null)
         {
             deviceInstanceGuid = device.Information.InstanceGuid;
             isWheel = device.Information.Type == SharpDX.DirectInput.DeviceType.Driving;
         }
     }
     state = null;
     if (device != null)
     {
         try
         {
             device.Acquire();
             state = device.GetCurrentState();
         }
         catch (Exception ex)
         {
             var error = ex;
         }
     }
     ShowDirectInputState(state);
 }
开发者ID:suvjunmd,项目名称:x360ce,代码行数:27,代码来源:DirectInputControl.cs

示例4: ShowDirectInputState

        List<string> ShowDirectInputState(Joystick device)
        {
            JoystickState state = null;
            if (device != null)
            {
                try
                {
                    device.Acquire();
                    state = device.GetCurrentState();
                }
                catch (Exception ex)
                {
                    var error = ex;
                }
            }

            if (state == null || state.Equals(oldState)) return actions;

            // Fill axis.
            Axis[0] = state.X;
            Axis[1] = state.Y;
            Axis[2] = state.Z;
            Axis[3] = state.RotationX;
            Axis[4] = state.RotationY;
            Axis[5] = state.RotationZ;

            oldState = state;
            actions.Clear();
            // X-axis.
            DiAxisTable.Rows[0][1] = state.X;
            DiAxisTable.Rows[0][2] = state.RotationX;
            DiAxisTable.Rows[0][3] = state.AccelerationX;
            DiAxisTable.Rows[0][4] = state.AngularAccelerationX;
            DiAxisTable.Rows[0][5] = state.ForceX;
            DiAxisTable.Rows[0][6] = state.TorqueX;
            DiAxisTable.Rows[0][7] = state.VelocityX;
            DiAxisTable.Rows[0][8] = state.AngularVelocityX;
            // Y-axis.
            DiAxisTable.Rows[1][1] = state.Y;
            DiAxisTable.Rows[1][2] = state.RotationY;
            DiAxisTable.Rows[1][3] = state.AccelerationY;
            DiAxisTable.Rows[1][4] = state.AngularAccelerationY;
            DiAxisTable.Rows[1][5] = state.ForceY;
            DiAxisTable.Rows[1][6] = state.TorqueY;
            DiAxisTable.Rows[1][7] = state.VelocityY;
            DiAxisTable.Rows[1][8] = state.AngularVelocityY;
            // Z-axis.
            DiAxisTable.Rows[2][1] = state.Z;
            DiAxisTable.Rows[2][2] = state.RotationZ;
            DiAxisTable.Rows[2][3] = state.AccelerationZ;
            DiAxisTable.Rows[2][4] = state.AngularAccelerationZ;
            DiAxisTable.Rows[2][5] = state.ForceZ;
            DiAxisTable.Rows[2][6] = state.TorqueZ;
            DiAxisTable.Rows[2][7] = state.VelocityZ;
            DiAxisTable.Rows[2][8] = state.AngularVelocityZ;

            var rows = DiAxisTable.Rows;
            var cols = DiAxisTable.Columns;
            int v;
            int axisNum;
            for (int r = 0; r < rows.Count; r++)
            {
                for (int c = 1; c < cols.Count; c++)
                {
                    if (System.DBNull.Value == rows[r][c]) continue;
                    v = (int)rows[r][c];
                    axisNum = (c - 1) * rows.Count + r + 1;
                    addAction(actions, v, "Axis", axisNum);
                }
            }

            bool[] buttons = state.Buttons;
            DiButtonsTextBox.Text = "";
            if (buttons != null)
            {
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        actions.Add(string.Format("Button {0}", i + 1));
                        if (DiButtonsTextBox.Text.Length > 0) DiButtonsTextBox.Text += " ";
                        DiButtonsTextBox.Text += (i + 1).ToString("00");
                    }
                }
            }
            // Sliders
            var sNum = 1;
            ProcessSlider(actions, state.Sliders, DiUvSliderTextBox, ref sNum);
            ProcessSlider(actions, state.AccelerationSliders, DiASliderTextBox, ref sNum);
            ProcessSlider(actions, state.ForceSliders, DiFSliderTextBox, ref sNum);
            ProcessSlider(actions, state.VelocitySliders, DiVSliderTextBox, ref sNum);

            // Point of view buttons
            int[] dPad = state.PointOfViewControllers;
            DiDPadTextBox.Text = "";
            if (dPad != null)
            {
                for (int i = 0; i < dPad.Length; i++)
                {
                    v = dPad[i];
//.........这里部分代码省略.........
开发者ID:XxRaPiDK3LLERxX,项目名称:nucleuscoop,代码行数:101,代码来源:DirectInputControl.cs

示例5: LoadJoysticks

        private void LoadJoysticks()
        {
            DirectInput di = new DirectInput();
            List<DeviceInstance> devices = new List<DeviceInstance>();

            devices.AddRange(di.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly));

            foreach (DeviceInstance i in devices) {
                if (i.Type == DeviceType.Joystick) {
                    Joystick j = new Joystick(di, i.InstanceGuid);
                    j.Acquire();
                    sticks.Add(j);
                    stickstate.Add(j.GetCurrentState());
                }
            }

            // set up a timer to poll joystick state at 10Hz
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            timer.Start();
        }
开发者ID:klasbj,项目名称:ButtonServer,代码行数:21,代码来源:MainWindow.xaml.cs

示例6: 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

示例7: tm1939StickHandlingLogic

        void tm1939StickHandlingLogic(Joystick stick, int id)
        {
            var state = stick.GetCurrentState(); 

            bool[] buttons = state.GetButtons(); // Stores the number of each button on the gamepad into the bool[] butons.

            String strButtonMap = tm1939GetButtonMap(buttons, id);

            _form.UseButtonMap(id, strButtonMap);
        }
开发者ID:FIRST1939,项目名称:2016ScoutingSystem,代码行数:10,代码来源:GameInput.cs

示例8: scanJoystickInputs

 private void scanJoystickInputs(NodeDevice device, Joystick joystick)
 {
     var state = joystick.GetCurrentState();
     foreach (var discreteInput in device.NodeDiscreteInputChildren)
     {
         int buttonIndex = Convert.ToInt32(discreteInput.Address.ToString());
         var buttons = state.GetButtons();
         discreteInput.Value = buttons[buttonIndex];
     }
     foreach (var analogInput in device.NodeAnalogInputChildren)
     {
         int rawValue = 0;
         if (analogInput.Code.ToString().StartsWith(Resources.Strings.PoVHat))
         {
             var povIndex = Convert.ToInt32(analogInput.Address.ToString());
             rawValue = state.GetPointOfViewControllers()[povIndex];
         }
         else
         {
             switch (analogInput.Address.ToString())
             {
                 case "X":
                     rawValue = state.X;
                     break;
                 case "Y":
                     rawValue = state.Y;
                     break;
                 case "Z":
                     rawValue = state.Z;
                     break;
                 case "RotationX":
                     rawValue = state.RotationX;
                     break;
                 case "RotationY":
                     rawValue = state.RotationY;
                     break;
                 case "RotationZ":
                     rawValue = state.RotationZ;
                     break;
             }
         }
         analogInput.Value = rawValue;
     }
 }
开发者ID:EdWeller,项目名称:SoapboxSnap,代码行数:44,代码来源:RuntimeDriver.cs

示例9: getFirstPressedButton

 private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment)
 {
     listenForAssignment = true;
     // Instantiate the joystick
     var joystick = new Joystick(directInput, controllerData.guid);
     // Acquire the joystick
     joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background));
     joystick.Properties.BufferSize = 128;
     joystick.Acquire();
     Boolean gotAssignment = false;
     while (listenForAssignment)
     {
         Boolean[] buttons = joystick.GetCurrentState().Buttons;
         for (int i = 0; i < buttons.Count(); i++)
         {
             if (buttons[i])
             {
                 Console.WriteLine("Got button at index " + i);
                 removeAssignmentsForControllerAndButton(controllerData.guid, i);
                 buttonAssignment.controller = controllerData;
                 buttonAssignment.joystick = joystick;
                 buttonAssignment.buttonIndex = i;
                 listenForAssignment = false;
                 gotAssignment = true;
             }
         }
     }
     if (!gotAssignment)
     {
         joystick.Unacquire();
     }
     return gotAssignment;
 }
开发者ID:mrbelowski,项目名称:r3e_crewchief_v2,代码行数:33,代码来源:ControllerConfiguration.cs

示例10: 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

示例11: getFirstPressedButton

 private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment)
 {
     Boolean gotAssignment = false;
     if (controllerData.guid == NETWORK_CONSOLE_CONTROLLER_GUID)
     {
         PCarsUDPreader gameDataReader = (PCarsUDPreader)GameStateReaderFactory.getInstance().getGameStateReader(GameDefinition.pCarsNetwork);
         int assignedButton = gameDataReader.getButtonIndexForAssignment();
         if (assignedButton != -1)
         {
             removeAssignmentsForControllerAndButton(controllerData.guid, assignedButton);
             buttonAssignment.controller = controllerData;
             buttonAssignment.buttonIndex = assignedButton;
             listenForAssignment = false;
             gotAssignment = true;
         }
     }
     else
     {
         listenForAssignment = true;
         // Instantiate the joystick
         var joystick = new Joystick(directInput, controllerData.guid);
         // Acquire the joystick
         joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background));
         joystick.Properties.BufferSize = 128;
         joystick.Acquire();
         while (listenForAssignment)
         {
             Boolean[] buttons = joystick.GetCurrentState().Buttons;
             for (int i = 0; i < buttons.Count(); i++)
             {
                 if (buttons[i])
                 {
                     Console.WriteLine("Got button at index " + i);
                     removeAssignmentsForControllerAndButton(controllerData.guid, i);
                     buttonAssignment.controller = controllerData;
                     buttonAssignment.joystick = joystick;
                     buttonAssignment.buttonIndex = i;
                     listenForAssignment = false;
                     gotAssignment = true;
                 }
             }
         }
         if (!gotAssignment)
         {
             joystick.Unacquire();
         }
     }
     return gotAssignment;
 }
开发者ID:mrbelowski,项目名称:r3e_crewchief_v3,代码行数:49,代码来源:ControllerConfiguration.cs

示例12: RefreshJoystickState

        private void RefreshJoystickState(Joystick joystick, ZXSpectrum.Joystick zxJoystick)
        {
            // Set BufferSize in order to use buffered data.
            // joystick.Properties.BufferSize = 128;
            // Poll events from joystick
            // joystick.Poll();
            // var datas = joystick.GetBufferedData();

            joystick.Poll();
            JoystickState currentState = joystick.GetCurrentState();

            ZXSpectrum.JoystickHorizontalPosition newHorizontalPosition = ZXSpectrum.JoystickHorizontalPosition.Center;
            if (currentState.X < 16383)
            {
                newHorizontalPosition = ZXSpectrum.JoystickHorizontalPosition.Left;
            }
            else if (currentState.X > 49150)
            {
                newHorizontalPosition = ZXSpectrum.JoystickHorizontalPosition.Right;
            }
            ZXSpectrum.JoystickVerticalPosition newVerticalPosition = ZXSpectrum.JoystickVerticalPosition.Center;
            if (currentState.Y < 16383)
            {
                newVerticalPosition = ZXSpectrum.JoystickVerticalPosition.Up;
            }
            else if (currentState.Y > 49150)
            {
                newVerticalPosition = ZXSpectrum.JoystickVerticalPosition.Down;
            }
            bool newButtonPressedState = currentState.Buttons[0];

            zxJoystick.RefreshCurrentPosition(newVerticalPosition, newHorizontalPosition, newButtonPressedState);
        }
开发者ID:laurentprudhon,项目名称:ZxSpectrumSimulator,代码行数:33,代码来源:JoystickAdapter.cs


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