> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XInputGetState

> XInputGetState

# XInputGetState

检索指定控制器的当前状态。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
DWORD XInputGetState(  
         DWORD dwUserIndex,  
         XINPUT_STATE * pState  
)  
```

<a id="parametersSection" />

### 参数

*dwUserIndex*   \_In\_\
类型：DWORD

与设备关联的玩家索引；取值范围为 0 到 `XUSER_MAX_COUNT - 1`。

*pState*   \_Out\_\
类型：[XINPUT\_STATE](/reference/input/xinputongameinput/structs/xinput_state)\*

指向 [XINPUT\_STATE](/reference/input/xinputongameinput/structs/xinput_state) 对象的指针，用于接收控制器的当前状态。

<a id="retvalSection" />

### 返回值

类型：DWORD

如果函数成功，则返回 `ERROR_SUCCESS`。

如果未连接控制器，函数将返回 `ERROR_DEVICE_NOT_CONNECTED`。

如果函数失败，将返回 WinError.h 中定义的错误代码。

<a id="remarksSection" />

## 备注

此函数分别报告左右扳机。在 DirectInput 中，这两个扳机共享同一个轴。

[XInputGetStateWithToken](/reference/input/xinputongameinput/functions/xinputgetstatewithtoken) 函数与之类似，但允许调用者提供 D3DX 帧管线令牌，将特定输入读数与图形帧相关联，以便后续在 PIX 中进行分析。

有关详细信息，请参阅 [XInputOnGameInput 包装器](/build/core-features/common/input/porting/input-porting-xinput#xinputWrapperSection)。

<a id="requirementsSection" />

## 要求

**头文件：** XInputOnGameInput.h

**库：** xgameruntime.lib

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

<a id="seealsoSection" />

## 另请参阅

[从 XInput 移植到 GameInput](/build/core-features/common/input/porting/input-porting-xinput)\
[XInputOnGameInput](/reference/input/xinputongameinput/xinputongameinput_members)


## Related topics

- [XInputGetStateWithToken](/zh-CN/reference/input/xinputongameinput/functions/xinputgetstatewithtoken.md)
- [XINPUT_STATE](/zh-CN/reference/input/xinputongameinput/structs/xinput_state.md)
- [XInputEnable](/zh-CN/reference/input/xinputongameinput/functions/xinputenable.md)
- [从 XInput 移植到 GameInput](/zh-CN/build/core-features/common/input/porting/input-porting-xinput.md)
- [XInputOnGameInput](/zh-CN/reference/input/xinputongameinput/xinputongameinput_members.md)
