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

# XInputSetStateEx

> XInputSetStateEx

# XInputSetStateEx

將震動資料傳送至指定的控制器。支援新型控制器的四馬達震動功能。

## 語法

```cpp theme={null}
DWORD XInputSetStateEx(  
         DWORD dwUserIndex,  
         const XINPUT_VIBRATION_EX * pVibration  
)  
```

### 參數

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

與裝置相關聯之玩家的索引；值的範圍為 0 到 `XUSER_MAX_COUNT - 1`。

*pVibration*   \_In\_\
類型：[XINPUT\_VIBRATION\_EX](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/structs/xinput_vibration_ex.md)\*

指向 [XINPUT\_VIBRATION\_EX](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/structs/xinput_vibration_ex.md) 物件的指標，該物件包含要傳送至控制器的震動資訊。

### 傳回值

類型：DWORD

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

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

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

## 備註

即使在與雙馬達控制器互動期間，呼叫此函式也是安全的。針對雙馬達控制器傳送至 `XInputSetStateEx` 的任何震動設定都會經過調整，以確保控制器仍能以最接近所傳送輸入的方式震動。因此，建議您在會呼叫 [XInputSetState](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/functions/xinputsetstate.md) 的情況下改為呼叫 `XInputSetStateEx`。

如需詳細資訊，請參閱 [XInputOnGameInput 包裝函式](https://docs.xbox.com/zh-TW/build/core-features/common/input/porting/input-porting-xinput.md#xinputWrapperSection)。

## 需求

**標頭：** XInputOnGameInput.h

**程式庫：** xgameruntime.lib

**支援的平台：** XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[從 XInput 移植到 GameInput](https://docs.xbox.com/zh-TW/build/core-features/common/input/porting/input-porting-xinput.md)\
[XInputOnGameInput](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/xinputongameinput_members.md)


## Related topics

- [XInputSetState](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/functions/xinputsetstate.md)
- [XINPUT_VIBRATION_EX](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/structs/xinput_vibration_ex.md)
- [XINPUT_VIBRATION](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/structs/xinput_vibration.md)
- [XInputOnGameInput (API 內容)](https://docs.xbox.com/zh-TW/reference/input/xinputongameinput/xinputongameinput_members.md)
- [從 XInput 移植到 GameInput](https://docs.xbox.com/zh-TW/build/core-features/common/input/porting/input-porting-xinput.md)
