Compartilhar via


IGameInputReading::GetGamepadState

Retrieve a view of the input reading that describes the state of a gamepad.

Syntax

bool GetGamepadState(  
         GameInputGamepadState* state  
)  

Parameters

state   _Out_
Type: GameInputGamepadState*

Interpretation of the input as a gamepad.

Return value

Type: bool

Returns true on successful interpretation of a gamepad.
Returns false when attempting to read an input that is not recognized as a gamepad.

Remarks

Call the IGameInputReading::GetInputKind method to see which Get*State functions will return a valid interpretation for some IGameInputReading. Each Get*State function has a corresponding entry in the IGameInputReading::GetInputKind enum. If you attempt to call a Get*State function where the corresponding IGameInputReading::GetInputKind flag is not set the function will return with default at rest values as well as a false return value.

The following C++ sample demonstrates how to read the gamepad state.

void PlayerCrouch(); 
void PlayerStand(); 
void PlayerReload(); 
void PlayerMove(float, float); 
void SetCameraOrientation(float, float); 
 
void ProcessGamepadState( 
    _In_ IGameInputReading * prevReading, 
    _In_ IGameInputReading * currentReading) noexcept 
{ 
    GameInputGamepadState prevState, currentState; 
    prevReading->GetGamepadState(&prevState); 
    currentReading->GetGamepadState(&currentState); 
 
    GameInputGamepadButtons changedButtons = prevState.buttons ^ currentState.buttons; 
    GameInputGamepadButtons pressedButtons = changedButtons & currentState.buttons; 
    GameInputGamepadButtons releasedButtons = changedButtons ^ pressedButtons; 
 
    if (pressedButtons & GameInputGamepadRightShoulder) 
    { 
        PlayerCrouch(); 
    } 
    else if (releasedButtons & GameInputGamepadRightShoulder) 
    { 
        PlayerStand(); 
    } 
 
    if (pressedButtons & GameInputGamepadLeftShoulder) 
    { 
        PlayerReload(); 
    } 
 
    PlayerMove(currentState.leftThumbstickX, currentState.leftThumbstickY); 
    SetCameraOrientation(currentState.rightThumbstickX, currentState.rightThumbstickY); 
}

Requirements

Header: GameInput.h

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

Input API Overview
IGameInputReading
IGameInputReading::GetInputKind