> ## 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::GetControllerAxisLabels

> 检索设备上通用控制器轴的标签。

检索设备上通用控制器轴的标签。

## 语法

```cpp theme={null}
uint32_t GetControllerAxisLabels(
    uint32_t labelArrayCount,
    GameInputLabel* labelArray
);
```

### 参数

*labelArrayCount*   \_In\_\
类型：uint32\_t

*labelArray* 中的元素数量。若要检索所有控制器轴标签，请传递 [GetControllerAxisCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md) 返回的值。

*labelArray*   \_Out\_writes\_to\_opt\_(labelArrayCount, return)\
类型：[GameInputLabel](https://docs.xbox.com/zh-CN/reference/input/gameinput/enums/gameinputlabel.md)\*

指向数组的指针，该数组为每个控制器轴接收一个标签。可以为 `nullptr`，在这种情况下不会写入任何内容，并且方法返回 0。

### 返回值

类型：uint32\_t

写入 *labelArray* 的元素数量。该值为 *labelArrayCount* 与设备上控制器轴标签数量中的较小者；如果 *labelArray* 为 `nullptr` 或设备没有控制器轴标签，则为 0。

## 备注

每个元素都是一个 [GameInputLabel](https://docs.xbox.com/zh-CN/reference/input/gameinput/enums/gameinputlabel.md) 值，用于标识印在相应轴上的标记（如果设备报告了该标记）。

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

标签数组的元素 *i* 描述的是，对于来自此设备的读数，[IGameInputReading::GetControllerAxisState](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrolleraxisstate.md) 返回的数组中索引 *i* 处的轴。

以下示例演示如何检索设备的控制器轴标签。

```cpp theme={null}
uint32_t axisCount = device->GetControllerAxisCount();
std::vector<GameInputLabel> axisLabels(axisCount);
axisLabels.resize(device->GetControllerAxisLabels(axisCount, axisLabels.data()));

std::vector<float> axisStates(reading->GetControllerAxisCount());
reading->GetControllerAxisState(static_cast<uint32_t>(axisStates.size()), axisStates.data());

for (size_t i = 0; i < axisLabels.size() && i < axisStates.size(); ++i)
{
    // axisLabels[i] is the label of the axis whose value is axisStates[i].
}
```

在 GameInput v3 及更早版本中，此信息可从 [GameInputControllerInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/deprecated/structs/gameinputcontrollerinfo.md) 结构的 `controllerAxisLabels` 成员中获取，该结构由 [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) 结构的 `controllerInfo` 成员引用。

## 要求

**头文件：** 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)\
[GetControllerAxisCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md)\
[GameInputLabel](https://docs.xbox.com/zh-CN/reference/input/gameinput/enums/gameinputlabel.md)\
[IGameInputReading::GetControllerAxisState](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrolleraxisstate.md)\
[IGameInputDevice](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## 版本历史

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


## Related topics

- [GameInputLabel](https://docs.xbox.com/zh-CN/reference/input/gameinput/enums/gameinputlabel.md)
- [IGameInputDevice::GetControllerAxisCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md)
- [IGameInputDevice::GetControllerButtonLabels](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttonlabels.md)
- [IGameInputDevice::GetControllerButtonCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md)
- [IGameInputDevice::GetControllerSwitchCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md)
