private void onCurrentState() { Console.Clear(); SlimDX.DirectInput.JoystickState state = joystick.currentState; Console.WriteLine("Controller:" + joystick.JoystickName); bool[] jsButtons = state.GetButtons(); int[] POVs = state.GetPointOfViewControllers(); int[] Axis = state.GetSliders(); Console.WriteLine("X: {0}, Y: {1},Z: {2}", state.X, state.Y, state.Z); Console.WriteLine("RX: {0}, RY: {1}, RZ: {2}", state.RotationX, state.RotationY, state.RotationZ); int i = 0; foreach (int Ax in Axis) { Console.WriteLine("Axel Nr {0}: {1}", i, Ax); i++; } foreach (int POV in POVs) { Console.WriteLine("POV Nr {0}: Aktiv", POV); } i = 0; foreach (bool button in jsButtons) { if (button) { Console.WriteLine("Knapp Nr {0}: Aktiv", i); } i++; } }
private byte[] DetectInput(byte index) { Stopwatch sw = new Stopwatch(); sw.Start(); SlimDX.DirectInput.JoystickState jState = dev.joystick.GetCurrentState(); bool input = false; byte[] b = new byte[] { 0, 0, 0 }; int[] axisNeutral = new int[] { jState.X, jState.Y, jState.Z, jState.RotationX, jState.RotationY, jState.RotationZ }; //gets the current axis positions and assumes them as neutral int[] slidersNeutral = new int[] { jState.GetSliders()[0], jState.GetSliders()[1] }; while (!input) { jState = dev.joystick.GetCurrentState(); bool[] buttons = jState.GetButtons(); //return bool for every button as array int[] pov = jState.GetPointOfViewControllers(); //returns int for every pov position as array int[] axis = new int[] { jState.X, jState.Y, jState.Z, jState.RotationX, jState.RotationY, jState.RotationZ }; //returns int for every slider position as array int[] sliders = new int[] { jState.GetSliders()[0], jState.GetSliders()[1] }; int i; i = 0; while (i < buttons.Length && !input) { if (buttons[i]) { input = true; b[0] = 0; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding button {0} to index {1}", i + 1, b[2]); return(b); } i++; } i = 0; while (i < axis.Length && !input) { // adding a deadzone, just to make sure user really presses the right direction if (axis[i] > axisNeutral[i] + 15000) { input = true; b[0] = 16; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding + axis {0} to index {1}", i + 1, b[2]); return(b); } // adding a deadzone, just to make sure user really presses the right direction else if (axis[i] < axisNeutral[i] - 15000) { input = true; b[0] = 17; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding - axis {0} to index {1}", i + 1, b[2]); return(b); } i++; } i = 0; while (i < sliders.Length && !input) { if (sliders[i] > slidersNeutral[i] + 15000) { input = true; b[0] = 48; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding + slider {0} to index {1}", i + 1, b[2]); return(b); } else if (sliders[i] < slidersNeutral[i] - 15000) { input = true; b[0] = 49; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding - slider {0} to index {1}", i + 1, b[2]); return(b); } i++; } i = 0; while (i < pov.Length && !input) { { switch (pov[i]) { case 0: input = true; b[0] = 32; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding DPad Up {0} to index {1}", i + 1, b[2]); return(b); case 9000: input = true; b[0] = 35; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding DPad Right {0} to index {1}", i + 1, b[2]); return(b); case 18000: input = true; b[0] = 33; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding DPad Down {0} to index {1}", i + 1, b[2]); return(b); case 27000: input = true; b[0] = 34; b[1] = (byte)i; b[2] = index; Console.WriteLine("Binding DPad Left {0} to index {1}", i + 1, b[2]); return(b); } } i++; } if (sw.ElapsedMilliseconds > 2000) { b[0] = 127; // this type defines an unsuccessful detection b[2] = index; break; } } return(b); }