private static bool[] CaptureControllerInput() { try { if (DXJoystick == null || !DXJoystick.Acquire().IsSuccess) { return(null); } bool[] flagArray = new bool[256]; DXJoystickState currentState = DXJoystick.GetCurrentState(); flagArray = currentState.GetButtons(); int length = flagArray.Length; if (currentState.X > 500) { flagArray[102] = true; } else if (currentState.X < -500) { flagArray[103] = true; } if (currentState.Y > 500) { flagArray[101] = true; } else if (currentState.Y < -500) { flagArray[100] = true; } return(flagArray); } catch { return(null); } }
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); } }
private void GetInput() { state = joystick.GetCurrentState(); Buttons = state.GetButtons(); Joystick[0] = state.X; Joystick[1] = state.Y; Joystick[2] = state.Z; Joystick[3] = state.RotationX; Joystick[4] = state.RotationY; Joystick[5] = state.RotationZ; Sliders = state.GetPointOfViewControllers(); for (int i = 0; i < 7; i++) { if ((Joystick[i] > 200) || (Joystick[i] < -200)) { Move(i, Joystick[i]); } } for (int i = 0; i < 10; i++) { if (Buttons[i]) { Move(i, 500); } } }
/// <summary>Initialises the joystick.</summary> private void InitialiseJoystick() { List<DI.Joystick> joysticks = GetAttachedJoysticks(); if(ControllerIndex < joysticks.Count) { _joystick = joysticks[ControllerIndex]; _joystickState = _joystick.GetCurrentState(); System.Diagnostics.Debug.WriteLine("Using joystick: " + _joystick.Information.InstanceName); } _joystickConnected = (_joystickState != null); }