private void UpdateGamepad(int gamePadIndex) { GamePadState oldState = currentGamepadStates[gamePadIndex]; currentGamepadStates[gamePadIndex] = GamePad.GetState(PLAYERS_INDICES[gamePadIndex], deadZone); bool connected = currentGamepadStates[gamePadIndex].IsConnected; if (IsGamePadConnected(ref oldState, ref currentGamepadStates[gamePadIndex])) { NotifyGamePadConnected(gamePadIndex); } else if (IsGamePadDisconnected(ref oldState, ref currentGamepadStates[gamePadIndex])) { NotifyGamePadDisconnected(gamePadIndex); } for (int buttonIndex = 0; buttonIndex < CHECK_BUTTONS.Length; ++buttonIndex) { Buttons button = CHECK_BUTTONS[buttonIndex]; if (IsButtonDown(button, ref oldState, ref currentGamepadStates[gamePadIndex])) { FireKeyPressed(gamePadIndex, KeyCodeHelper.FromButton(button), gamePadIndex); } else if (IsButtonUp(button, ref oldState, ref currentGamepadStates[gamePadIndex])) { FireKeyReleased(gamePadIndex, KeyCodeHelper.FromButton(button), gamePadIndex); } } }
////////////////////////////////////////////////////////////////////////////// #region Keyboard private void UpdateKeyboard() { KeyboardState oldState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); Keys[] oldKeys = oldState.GetPressedKeys(); Keys[] newKeys = currentKeyboardState.GetPressedKeys(); for (int i = 0; i < newKeys.Length; ++i) { if (!oldKeys.Contains(newKeys[i])) { FireKeyPressed(-1, KeyCodeHelper.FromKey(newKeys[i]), REPEAT_KEYBOARD_INDEX); } } for (int i = 0; i < oldKeys.Length; ++i) { if (!newKeys.Contains(oldKeys[i])) { FireKeyReleased(-1, KeyCodeHelper.FromKey(oldKeys[i]), REPEAT_KEYBOARD_INDEX); } } }
public override bool IsKeyPressed(KeyCode code) { return(currentKeyboardState.IsKeyDown(KeyCodeHelper.ToKey(code))); }
public override bool IsButtonPressed(int playerIndex, KeyCode code) { return(currentGamepadStates[playerIndex].IsButtonDown(KeyCodeHelper.ToButton(code))); }