Exemple #1
0
        private void detectButton(int ind)
        {
            // Still axes position
            dev.joystick.Poll();
            int[] axes = ControllerDevice.GetAxes(dev.joystick.GetCurrentState());

            byte[] res;

            // Wait until button pressed
            while (isBinding)
            {
                res = ifPressed(axes);
                if (res != null)
                {
                    // Map Button
                    dev.mapping[ind * 2] = res[0];

                    dev.mapping[(ind * 2) + 1] = res[1];
                    Invoke((MethodInvoker) delegate { Hide(); });
                    DialogResult = DialogResult.OK;
                    isBinding    = false;
                    break;
                }
            }
        }
Exemple #2
0
        private byte[] ifPressed(int[] axesStart)
        {
            dev.joystick.Poll();
            JoystickState jState = dev.joystick.GetCurrentState();

            bool[] buttons = jState.GetButtons();
            int[]  dPads   = jState.GetPointOfViewControllers();
            int[]  axes    = ControllerDevice.GetAxes(jState);

            // Buttons
            int i = 0;

            foreach (bool button in buttons)
            {
                if (button)
                {
                    return new byte[] { 0, (byte)i }
                }
                ;
                i++;
            }

            // dPads
            i = 0;
            foreach (int dPad in dPads)
            {
                bool[] dp = getPov(dPad);
                for (int x = 0; x < 4; x++)
                {
                    if (dp[x])
                    {
                        return new byte[] { (byte)(32 + x), (byte)i }
                    }
                    ;
                }
                i++;
            }

            // Axes
            i = 0;
            foreach (int axis in axes)
            {
                if (axis != axesStart[i])
                {
                    return new byte[] { 16, (byte)i }
                }
                ;

                i++;
            }
            return(null);
        }