> ## 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](/zh-TW/reference/input/xinputongameinput/structs/xinput_state)\*

指向接收控制器目前狀態之 [XINPUT\_STATE](/zh-TW/reference/input/xinputongameinput/structs/xinput_state) 物件的指標。

<a id="retvalSection" />

### 傳回值

類型：DWORD

如果函式成功，會傳回 `ERROR_SUCCESS`。

如果控制器未連接，函式會傳回 `ERROR_DEVICE_NOT_CONNECTED`。

如果函式失敗，會傳回 WinError.h 中定義的錯誤碼。

<a id="remarksSection" />

## 備註

此函式會分別回報左扳機和右扳機。在 DirectInput 中，這兩個扳機共用同一個軸。

[XInputGetStateWithToken](/zh-TW/reference/input/xinputongameinput/functions/xinputgetstatewithtoken) 函式與此類似，但可讓呼叫端提供 D3DX 畫面管線權杖，將特定輸入讀數與圖形畫面產生關聯，以便稍後在 PIX 中進行分析。

如需詳細資訊，請參閱 [XInputOnGameInput 包裝函式](/zh-TW/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](/zh-TW/build/core-features/common/input/porting/input-porting-xinput)\
[XInputOnGameInput](/zh-TW/reference/input/xinputongameinput/xinputongameinput_members)


## Related topics

- [XInputGetState](/reference/input/xinputongameinput/functions/xinputgetstate.md)
- [XInputGetStateWithToken](/reference/input/xinputongameinput/functions/xinputgetstatewithtoken.md)
