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

> 获取设备上通用控制器开关（例如帽子开关和方向键）的数量。

获取设备上通用控制器开关（例如帽子开关和方向键）的数量。

## 语法

```cpp theme={null}
uint32_t GetControllerSwitchCount();
```

### 参数

此方法没有参数。

### 返回值

类型：uint32\_t

设备上控制器开关的数量；如果设备没有控制器开关，则为 0。

## 备注

控制器开关是设备上未映射的原始多位置开关，例如帽子开关和方向键。当 [GetSupportedInput](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedinput.md) 返回的值包含 `GameInputKindControllerSwitch` 时，设备具有控制器开关。来自该设备且包含 `GameInputKindControllerSwitch` 的读数会通过 [IGameInputReading::GetControllerSwitchCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchcount.md) 报告相同数量的开关。

使用返回的值来确定传递给 [GetControllerSwitchInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchinfo.md) 或 [IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchstate.md) 的数组大小。在设备保持连接期间，开关的数量不会更改。

在 GameInput v3 及更早版本中，此信息可从 [GameInputControllerInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/deprecated/structs/gameinputcontrollerinfo.md) 结构的 `controllerSwitchCount` 成员中获取，该结构由 [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)\
[GetControllerSwitchInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchinfo.md)\
[IGameInputReading::GetControllerSwitchCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchcount.md)\
[IGameInputReading::GetControllerSwitchState](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchstate.md)\
[IGameInputDevice](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)

## 版本历史

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


## Related topics

- [IGameInputDevice::GetControllerSwitchInfo](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerswitchinfo.md)
- [GetControllerSwitchCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getcontrollerswitchcount.md)
- [IGameInputDevice::GetControllerAxisCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrolleraxiscount.md)
- [IGameInputDevice::GetControllerButtonCount](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttoncount.md)
- [IGameInputDevice::GetControllerButtonLabels](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontrollerbuttonlabels.md)
