> ## 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-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md) 返回的值。

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

指向数组的指针，该数组为每个力反馈电机接收一个结构。可以为 `nullptr`，在这种情况下不会写入任何内容，并且方法返回 0。

### 返回值

类型：uint32\_t

写入 *infoArray* 的元素数量。该值为 *infoArrayCount* 与设备上力反馈电机数量中的较小者；如果 *infoArray* 为 `nullptr` 或设备没有力反馈电机，则为 0。

## 备注

每个元素都是一个 [GameInputForceFeedbackMotorInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/structs/gameinputforcefeedbackmotorinfo.md) 结构，用于描述相应电机驱动的轴以及它支持的力反馈效果类型。

调用 [GetForceFeedbackMotorCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getforcefeedbackmotorcount.md) 获取力反馈电机的数量，分配该大小的数组，然后调用 `GetForceFeedbackMotorInfo` 填充该数组。如果 *infoArrayCount* 小于力反馈电机的数量，则只写入前 *infoArrayCount* 个元素。在设备保持连接期间，设备的力反馈电机不会更改，因此你可以只查询一次并缓存结果。

信息数组的元素 *i* 描述的是电机索引为 *i* 的电机。将该索引用作 [CreateForceFeedbackEffect](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_createforcefeedbackeffect.md)、[IsForceFeedbackMotorPoweredOn](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_isforcefeedbackmotorpoweredon.md) 和 [SetForceFeedbackMotorGain](https://docs.xbox.com/zh-CN/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-CN/reference/input/gameinput/deprecated/interfaces/igameinputdevice/methods/igameinputdevice_getdeviceinfo.md) 返回的 [GameInputDeviceInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/deprecated/structs/gameinputdeviceinfo.md) 结构的 `forceFeedbackMotorInfo` 成员中获取。

## 要求

**头文件：** GameInput.h

**库：** gameinput.lib

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

## 另请参阅

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

## 版本历史

| 版本 | 变更 |
| - | - |
| **v4** | 引入。 |


## Related topics

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