> ## 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.

# IGameInputDevice::GetForceFeedbackMotorInfo

> 擷取裝置上力回饋馬達的相關資訊，例如其支援的軸和效果類型。

擷取裝置上力回饋馬達的相關資訊，例如其支援的軸和效果類型。

## 語法

```cpp theme={null}
uint32_t GetForceFeedbackMotorInfo(
    uint32_t infoArrayCount,
    GameInputForceFeedbackMotorInfo* infoArray
);
```

### 參數

*infoArrayCount*   \_In\_\
類型：uint32\_t

*infoArray* 中的元素數目。若要擷取所有力回饋馬達，請傳遞 [GetForceFeedbackMotorCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md) 傳回的值。

*infoArray*   \_Out\_writes\_to\_opt\_(infoArrayCount, return)\
類型：[GameInputForceFeedbackMotorInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputforcefeedbackmotorinfo.md)\*

指向陣列的指標，此陣列會針對每個力回饋馬達接收一個結構。可以是 `nullptr`，在此情況下不會寫入任何內容，且方法會傳回 0。

### 傳回值

類型：uint32\_t

寫入 *infoArray* 的元素數目。此值為 *infoArrayCount* 與裝置上力回饋馬達數目兩者中的較小值；如果 *infoArray* 為 `nullptr` 或裝置沒有力回饋馬達，則為 0。

## 備註

每個元素都是一個 [GameInputForceFeedbackMotorInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputforcefeedbackmotorinfo.md) 結構，描述對應馬達所驅動的軸及其支援的力回饋效果類型。

呼叫 [GetForceFeedbackMotorCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md) 以取得力回饋馬達數目，配置該大小的陣列，然後呼叫 `GetForceFeedbackMotorInfo` 加以填入。如果 *infoArrayCount* 小於力回饋馬達數目，則只會寫入前 *infoArrayCount* 個元素。在裝置連線期間，裝置的力回饋馬達不會變更，因此您可以只查詢一次並快取結果。

資訊陣列的元素 *i* 描述馬達索引為 *i* 的馬達。將該索引當作 [CreateForceFeedbackEffect](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_createforcefeedbackeffect.md)、[IsForceFeedbackMotorPoweredOn](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_isforcefeedbackmotorpoweredon.md) 和 [SetForceFeedbackMotorGain](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_setforcefeedbackmotorgain.md) 的 *motorIndex* 參數使用。

下列範例示範如何擷取裝置的力回饋馬達。

```cpp theme={null}
uint32_t motorCount = device->GetForceFeedbackMotorCount();
std::vector<GameInputForceFeedbackMotorInfo> motorInfo(motorCount);
motorInfo.resize(device->GetForceFeedbackMotorInfo(motorCount, motorInfo.data()));

for (uint32_t motorIndex = 0; motorIndex < motorInfo.size(); ++motorIndex)
{
    if (motorInfo[motorIndex].isConstantEffectSupported)
    {
        GameInputForceFeedbackParams params = {};
        params.kind = GameInputForceFeedbackConstant;
        // Fill in the remaining effect parameters...

        Microsoft::WRL::ComPtr<IGameInputForceFeedbackEffect> effect;
        device->CreateForceFeedbackEffect(motorIndex, &params, &effect);
    }
}
```

在 GameInput v3 及更早版本中，此資訊可從 [IGameInputDevice::GetDeviceInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/interfaces/igameinputdevice/methods/igameinputdevice_getdeviceinfo.md) 所傳回 [GameInputDeviceInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/structs/gameinputdeviceinfo.md) 結構的 `forceFeedbackMotorInfo` 成員取得。

## 需求

**標頭：** GameInput.h

**程式庫：** gameinput.lib

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

## 另請參閱

[GameInput 概觀](https://docs.xbox.com/zh-TW/build/core-features/common/input/overviews/input-overview.md)\
[GetForceFeedbackMotorCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md)\
[GameInputForceFeedbackMotorInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputforcefeedbackmotorinfo.md)\
[CreateForceFeedbackEffect](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_createforcefeedbackeffect.md)\
[IsForceFeedbackMotorPoweredOn](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_isforcefeedbackmotorpoweredon.md)\
[SetForceFeedbackMotorGain](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_setforcefeedbackmotorgain.md)\
[GameInput 上的力回饋](https://docs.xbox.com/zh-TW/build/core-features/common/input/advanced/input-forcefeedback.md)\
[IGameInputDevice](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## 版本歷程記錄

| 版本 | 變更 |
| - | - |
| **v4** | 已推出。 |


## Related topics

- [GameInputForceFeedbackMotorInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputforcefeedbackmotorinfo.md)
- [GameInputFeedbackAxes](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputfeedbackaxes.md)
- [GameInput 上的力回饋](https://docs.xbox.com/zh-TW/build/core-features/common/input/advanced/input-forcefeedback.md)
- [IGameInputDevice::GetForceFeedbackMotorCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md)
- [IGameInputForceFeedbackEffect::GetDevice](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputforcefeedbackeffect/methods/igameinputforcefeedbackeffect_getdevice.md)
