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

> 获取唯一标识输入设备的应用本地 ID。

获取唯一标识输入设备的应用本地 ID。

## 语法

```cpp theme={null}
void GetDeviceId(
    APP_LOCAL_DEVICE_ID* deviceId
);
```

### 参数

*deviceId*   \_Out\_\
类型：[APP\_LOCAL\_DEVICE\_ID](https://docs.xbox.com/zh-CN/reference/system/xuser/structs/app_local_device_id.md)\*

接收设备的应用本地 ID。

### 返回值

类型：void

## 备注

设备 ID 是应用本地 ID：一个能够唯一标识设备的 256 位哈希值。只要设备连接到相同的 USB 端口，该 ID 对于给定设备保持不变，即使应用重新运行或系统重启也是如此。该哈希值部分由调用应用和系统的特定信息生成，因此同一设备在不同应用中具有不同的 ID。

由于该 ID 是稳定的，你可以将其存储下来以记住某个设备（例如用户首选的控制器），之后再通过调用 [IGameInput::FindDeviceFromId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinput/methods/igameinput_finddevicefromid.md) 查找对应的设备对象。

对于作为组合设备上多个接口之一的设备，请使用 [IGameInputDevice::GetDeviceRootId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getdevicerootid.md) 获取根设备的 ID。如果设备不属于组合设备，则设备 ID 与根设备 ID 相同。

在 GameInput v3 及更早版本中，此信息可从 [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) 结构的 `deviceId` 成员中获取。

## 要求

**头文件：** 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)\
[IGameInputDevice](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)\
[IGameInputDevice::GetDeviceRootId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getdevicerootid.md)\
[IGameInput::FindDeviceFromId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinput/methods/igameinput_finddevicefromid.md)\
[APP\_LOCAL\_DEVICE\_ID](https://docs.xbox.com/zh-CN/reference/system/xuser/structs/app_local_device_id.md)

## 版本历史

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


## Related topics

- [IGameInputDevice::GetDeviceRootId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getdevicerootid.md)
- [IGameInputDevice::IsConnected](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_isconnected.md)
- [用户与输入设备](https://docs.xbox.com/zh-CN/build/core-features/common/user/users-input-devices.md)
- [IGameInputDevice::GetContainerId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getcontainerid.md)
- [IGameInputDevice::GetVendorId](https://docs.xbox.com/zh-CN/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getvendorid.md)
