> ## 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/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md) から返された値を渡します。

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

コントローラー スイッチごとに 1 つの構造体を受け取る配列へのポインター。`nullptr` を指定できます。その場合、何も書き込まれず、メソッドは 0 を返します。

### 戻り値

型: uint32\_t

*infoArray* に書き込まれた要素の数。これは *infoArrayCount* とデバイス上のコントローラー スイッチの数のうち小さい方の値です。*infoArray* が `nullptr` の場合、またはデバイスにコントローラー スイッチがない場合は 0 です。

## 解説

各要素は [GameInputControllerSwitchInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md) 構造体であり、対応するスイッチの種類 (2 方向、4 方向、または 8 方向。[GameInputSwitchKind](https://docs.xbox.com/ja-jp/reference/input/gameinput/enums/gameinputswitchkind.md) 値として表されます) と、各位置のラベルを記述します。

[GetControllerSwitchCount](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md) を呼び出してコントローラー スイッチの数を取得し、そのサイズの配列を割り当ててから、`GetControllerSwitchInfo` を呼び出して配列にデータを格納します。*infoArrayCount* がコントローラー スイッチの数より小さい場合は、先頭から *infoArrayCount* 個の要素のみが書き込まれます。デバイスが接続されている間、デバイスのコントローラー スイッチは変化しないため、一度クエリを実行して結果をキャッシュできます。

情報配列の要素 *i* は、このデバイスからの読み取りについて [IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/ja-jp/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 以前では、この情報は [IGameInputDevice::GetDeviceInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/deprecated/interfaces/igameinputdevice/methods/igameinputdevice_getdeviceinfo.md) から返される [GameInputDeviceInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/deprecated/structs/gameinputdeviceinfo.md) 構造体の `controllerInfo` メンバーが参照する [GameInputControllerInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/deprecated/structs/gameinputcontrollerinfo.md) 構造体の `controllerSwitchInfo` メンバーから取得できました。

## 要件

**ヘッダー:** GameInput.h

**ライブラリ:** gameinput.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体、XBOX Series 本体

## 関連項目

[GameInput の概要](https://docs.xbox.com/ja-jp/build/core-features/common/input/overviews/input-overview.md)\
[GetControllerSwitchCount](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md)\
[GameInputControllerSwitchInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md)\
[GameInputSwitchKind](https://docs.xbox.com/ja-jp/reference/input/gameinput/enums/gameinputswitchkind.md)\
[IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchstate.md)\
[IGameInputDevice](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## バージョン履歴

| バージョン | 変更内容 |
| - | - |
| **v4** | 導入されました。 |


## Related topics

- [GameInputControllerSwitchInfo](https://docs.xbox.com/ja-jp/reference/input/gameinput/structs/gameinputcontrollerswitchinfo.md)
- [IGameInputDevice::GetControllerSwitchCount](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchcount.md)
- [IGameInputDevice::GetControllerAxisCount](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md)
- [IGameInputDevice::GetControllerButtonCount](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md)
- [IGameInputDevice::GetControllerAxisLabels](https://docs.xbox.com/ja-jp/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxislabels.md)
