/// <summary> /// Use the specified control and release it to default state after a moment. /// For example, press and release a specified button, or move and return an extreme analog stick position. /// </summary> /// <param name="control">Which control to use.</param> /// <param name="controllerIndex">Which controller to use.</param> /// <param name="holdTimeMS">How many milliseconds to hold the button down.</param> public void Use(GamePadControl control, int controllerIndex = 0, int holdTimeMS = 50) { EnsureInitialized(); SetControl(control, controllerIndex); Thread.Sleep(holdTimeMS); ReleaseControl(control, controllerIndex); }
/// <summary>Puts the the specified control in the simulated "fully off" state.</summary> /// <param name="control">Which control to set.</param> /// <param name="controllerIndex">The index of the controller to set this state for.</param> public void ReleaseControl(GamePadControl control, int controllerIndex = 0) { EnsureInitialized(); int i = controllerIndex; if (isPluggedIn[i]) { var flagsToSet = Enum.GetValues(typeof(GamePadControl)).Cast<GamePadControl>().Where(c => c != GamePadControl.None && (control & c) != 0); foreach (var flag in flagsToSet) { if (flag <= GamePadControl.Y) { State[i].Buttons &= ~flag; } else { switch (flag) { case GamePadControl.LeftTrigger: State[i].LeftTrigger = 0; break; case GamePadControl.RightTrigger: State[i].RightTrigger = 0; break; case GamePadControl.LeftStickLeft: State[i].LeftStickX = 0; break; case GamePadControl.LeftStickRight: State[i].LeftStickX = 0; break; case GamePadControl.LeftStickUp: State[i].LeftStickY = 0; break; case GamePadControl.LeftStickDown: State[i].LeftStickY = 0; break; case GamePadControl.RightStickLeft: State[i].RightStickX = 0; break; case GamePadControl.RightStickRight: State[i].RightStickX = 0; break; case GamePadControl.RightStickUp: State[i].RightStickY = 0; break; case GamePadControl.RightStickDown: State[i].RightStickY = 0; break; } } } Update(controllerIndex); } }
private static bool AnyKeyIsPressedForControl(Dictionary <Key, GamePadControl> map, GamePadControl control) { return(map.Any(entry => entry.Value == control && Keyboard.IsKeyDown(entry.Key))); }