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

> 擷取裝置上一般控制器按鈕的標籤。

擷取裝置上一般控制器按鈕的標籤。

## 語法

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

### 參數

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

*labelArray* 中的元素數目。若要擷取所有控制器按鈕標籤，請傳遞 [GetControllerButtonCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md) 傳回的值。

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

指向陣列的指標，此陣列會針對每個控制器按鈕接收一個標籤。可以是 `nullptr`，在此情況下不會寫入任何內容，且方法會傳回 0。

### 傳回值

類型：uint32\_t

寫入 *labelArray* 的元素數目。此值為 *labelArrayCount* 與裝置上控制器按鈕標籤數目兩者中的較小值；如果 *labelArray* 為 `nullptr` 或裝置沒有控制器按鈕標籤，則為 0。

## 備註

每個元素都是一個 [GameInputLabel](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputlabel.md) 值，用來識別對應按鈕上印製的標記 (如果裝置有回報的話)。

呼叫 [GetControllerButtonCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md) 以取得控制器按鈕標籤數目，配置該大小的陣列，然後呼叫 `GetControllerButtonLabels` 加以填入。如果 *labelArrayCount* 小於控制器按鈕標籤數目，則只會寫入前 *labelArrayCount* 個元素。在裝置連線期間，裝置的控制器按鈕標籤不會變更，因此您可以只查詢一次並快取結果。

標籤陣列的元素 *i* 描述此裝置之讀數的 [IGameInputReading::GetControllerButtonState](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerbuttonstate.md) 所傳回陣列中索引 *i* 處的按鈕。

下列範例示範如何擷取裝置的控制器按鈕標籤。

```cpp theme={null}
uint32_t buttonCount = device->GetControllerButtonCount();
std::vector<GameInputLabel> buttonLabels(buttonCount);
buttonLabels.resize(device->GetControllerButtonLabels(buttonCount, buttonLabels.data()));

std::unique_ptr<bool[]> buttonStates(new bool[buttonCount]);
uint32_t stateCount = reading->GetControllerButtonState(buttonCount, buttonStates.get());

for (uint32_t i = 0; i < buttonLabels.size() && i < stateCount; ++i)
{
    // buttonLabels[i] is the label of the button whose state is buttonStates[i].
}
```

在 GameInput v3 及更早版本中，此資訊可從 [GameInputControllerInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/structs/gameinputcontrollerinfo.md) 結構的 `controllerButtonLabels` 成員取得，該結構由 [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) 結構的 `controllerInfo` 成員參考。

## 需求

**標頭：** 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)\
[GetControllerButtonCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md)\
[GameInputLabel](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputlabel.md)\
[IGameInputReading::GetControllerButtonState](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerbuttonstate.md)\
[IGameInputDevice](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## 版本歷程記錄

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


## Related topics

- [GameInputLabel](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputlabel.md)
- [IGameInputDevice::GetControllerButtonCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md)
- [IGameInputDevice::GetControllerAxisLabels](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxislabels.md)
- [IGameInputDevice::GetControllerAxisCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md)
- [IGameInputDevice::GetGamepadInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getgamepadinfo.md)
