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

> 擷取裝置上一般控制器切換開關 (例如苦力帽開關和方向鍵) 的相關資訊。

擷取裝置上一般控制器切換開關 (例如苦力帽開關和方向鍵) 的相關資訊。

## 語法

```cpp theme={null}
uint32_t GetControllerSwitchInfo(
    uint32_t infoArrayCount,
    GameInputControllerSwitchInfo* infoArray
);
```

### 參數

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

*infoArray* 中的元素數目。若要擷取所有控制器切換開關，請傳遞 [GetControllerSwitchCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md) 傳回的值。

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

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

### 傳回值

類型：uint32\_t

寫入 *infoArray* 的元素數目。此值為 *infoArrayCount* 與裝置上控制器切換開關數目兩者中的較小值；如果 *infoArray* 為 `nullptr` 或裝置沒有控制器切換開關，則為 0。

## 備註

每個元素都是一個 [GameInputControllerSwitchInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md) 結構，描述對應切換開關的類型 (雙向、四向或八向，以 [GameInputSwitchKind](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputswitchkind.md) 值表示) 及其每個位置的標籤。

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

資訊陣列的元素 *i* 描述此裝置之讀數的 [IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchstate.md) 所傳回陣列中索引 *i* 處的切換開關。

下列範例示範如何擷取裝置的控制器切換開關。

```cpp theme={null}
uint32_t switchCount = device->GetControllerSwitchCount();
std::vector<GameInputControllerSwitchInfo> switchInfo(switchCount);
switchInfo.resize(device->GetControllerSwitchInfo(switchCount, switchInfo.data()));

std::vector<GameInputSwitchPosition> switchStates(reading->GetControllerSwitchCount());
reading->GetControllerSwitchState(static_cast<uint32_t>(switchStates.size()), switchStates.data());

for (size_t i = 0; i < switchInfo.size() && i < switchStates.size(); ++i)
{
    // switchInfo[i] describes the switch whose position is switchStates[i].
}
```

在 GameInput v3 及更早版本中，此資訊可從 [GameInputControllerInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/deprecated/structs/gameinputcontrollerinfo.md) 結構的 `controllerSwitchInfo` 成員取得，該結構由 [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)\
[GetControllerSwitchCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md)\
[GameInputControllerSwitchInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md)\
[GameInputSwitchKind](https://docs.xbox.com/zh-TW/reference/input/gameinput/enums/gameinputswitchkind.md)\
[IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchstate.md)\
[IGameInputDevice](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## 版本歷程記錄

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


## Related topics

- [GameInputControllerSwitchInfo](https://docs.xbox.com/zh-TW/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md)
- [IGameInputDevice::GetControllerSwitchCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md)
- [IGameInputDevice::GetControllerAxisCount](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.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)
