> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GameInput 中的觸覺回饋

> GameInput 中的觸覺回饋

GameInput 所公開的觸覺回饋功能已與 Windows 音訊系統整合，以確保將波形資料高效能且穩健地串流至相容裝置。支援觸覺回饋之裝置的音訊需求，與一般桌上型喇叭或耳機非常相似。GameInput 會結合慣例和製造商指定的中繼資料，將輸入裝置與用於觸覺回饋播放的音訊端點連結起來。

<a id="requirementsSection" />

## 需求

1. 裝置必須在 Windows 中被辨識為音訊來源。連線媒介 (USB、Bluetooth® 等) 並不重要。
2. 裝置公開的觸覺回饋端點不得超過一個。
3. 裝置公開的觸覺回饋位置不得超過八個。
4. 裝置連線之後，不得修改其觸覺回饋功能。
5. 裝置不得有多個格式 (每個樣本的位元數和每秒樣本數) 完全相同的音訊端點。
6. 裝置的音訊端點必須呈現與裝置其他部分相同的[容器識別碼](https://learn.microsoft.com/windows-hardware/drivers/install/container-ids)。
7. 裝置必須有登錄項目，以明確識別觸覺回饋端點。格式如下：

   * 觸覺回饋裝置會列舉在登錄的 `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GameInput\Devices` 中。
   * 特定裝置機碼是廠商識別碼、產品識別碼、使用方式頁面和使用方式識別碼的組合，格式為十六進位字串。
   * `HapticSamplesPerSecond` 是 DWORD 值，用於識別觸覺回饋端點格式的每秒樣本數 (Hz)。
   * `HapticsBitsPerSample` 是 DWORD 值，用於識別觸覺回饋端點格式的樣本位元數 (樣本大小)。
   * `HapticLocations` 是觸覺回饋位置 GUID 的 BYTE 陣列。此陣列必須包含一到八個 GUID，對應至觸覺回饋聲道對應。

   為了更清楚說明，請考慮下列範例裝置：

   | 欄位 | 值 |
   | - | - |
   | 廠商識別碼 | 0x045e |
   | 產品識別碼 | 0x1234 |
   | 使用方式頁面 | 0x0001 |
   | 使用方式識別碼 | 0x0005 |
   | 取樣頻率 | 0x0fa0 |
   | 樣本大小 | 0x0010 |
   | 觸覺回饋位置 | GAMEINPUT\_HAPTIC\_LOCATION\_GRIP\_LEFT, GAMEINPUT\_HAPTIC\_LOCATION\_GRIP\_RIGHT |

   相關聯的觸覺回饋登錄項目如下所示：

```
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GameInput\Devices\045E123400010005]
    "HapticSamplesPerSecond"=dword:00000fa0
    "HapticBitsPerSample"=dword:00000010
    "HapticLocations"=hex:c2,07,c7,08,bb,66,6c,40,a8,4a,df,e0,85,12,0a,92,77,0b,5a,\
    15,b2,8b,db,40,86,90,b6,d4,11,26,df,c1
```

### 觸覺回饋位置

目前已定義下列一般用途的觸覺回饋位置 GUID：

```cpp theme={null}
// { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
DEFINE_GUID(GAMEINPUT_HAPTIC_LOCATION_NONE, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);

// { 0xc2, 0x07, 0xc7, 0x08, 0xbb, 0x66, 0x6c, 0x40, 0xa8, 0x4a, 0xdf, 0xe0, 0x85, 0x12, 0x0a, 0x92 }
DEFINE_GUID(GAMEINPUT_HAPTIC_LOCATION_GRIP_LEFT, 0x08c707c2, 0x66bb, 0x406c, 0xa8, 0x4a, 0xdf, 0xe0, 0x85, 0x12, 0x0a, 0x92);

// { 0x77, 0x0b, 0x5a, 0x15, 0xb2, 0x8b, 0xdb, 0x40, 0x86, 0x90, 0xb6, 0xd4, 0x11, 0x26, 0xdf, 0xc1 }
DEFINE_GUID(GAMEINPUT_HAPTIC_LOCATION_GRIP_RIGHT, 0x155a0b77, 0x8bb2, 0x40db, 0x86, 0x90, 0xb6, 0xd4, 0x11, 0x26, 0xdf, 0xc1);

// { 0x96, 0xd8, 0xe4, 0x8d, 0x59, 0x55, 0x81, 0x40, 0x86, 0xe5, 0x17, 0x24, 0xcc, 0x07, 0xc6, 0xbc }
DEFINE_GUID(GAMEINPUT_HAPTIC_LOCATION_TRIGGER_LEFT, 0x8de4d896, 0x5559, 0x4081, 0x86, 0xe5, 0x17, 0x24, 0xcc, 0x07, 0xc6, 0xbc);

// { 0x57, 0xb5, 0x0c, 0xff, 0xf5, 0x3a, 0x6b, 0x40, 0x8b, 0x0f, 0x55, 0x5a, 0x2d, 0x92, 0xa2, 0x20 }
DEFINE_GUID(GAMEINPUT_HAPTIC_LOCATION_TRIGGER_RIGHT, 0xff0cb557, 0x3af5, 0x406b, 0x8b, 0x0f, 0x55, 0x5a, 0x2d, 0x92, 0xa2, 0x20);
```

請注意，在上述範例中，GUID 是使用其記憶體內部的 Little Endian 表示法序列化至登錄。

<a id="seealsoSection" />

## 參考 API 文件

* [GameInput (API 內容)](/zh-TW/reference/input/gameinput/gameinput_members)
  * 結構
    * [GameInputHapticInfo](/zh-TW/reference/input/gameinput/structs/gameinputhapticinfo)

## 另請參閱

[GetHapticInfo](/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_gethapticinfo)

[GameInputHapticInfo](/zh-TW/reference/input/gameinput/structs/gameinputhapticinfo)

[GameInput 概觀](/zh-TW/build/core-features/common/input/overviews/input-overview)

[Windows 音訊](/zh-TW/build/console-features/audio/overviews/audio)


## Related topics

- [GameInput 中的传感器](/zh-CN/build/core-features/common/input/hardware/input-hardware-sensors.md)
- [GameInput 中的触觉反馈](/zh-CN/build/core-features/common/input/hardware/input-hardware-haptics.md)
- [GameInput](/zh-CN/reference/input/gameinput/gameinput_members.md)
- [GameInput 常见问题](/zh-CN/build/core-features/common/input/overviews/input-faq.md)
- [从 XInput 移植到 GameInput](/zh-CN/build/core-features/common/input/porting/input-porting-xinput.md)
