# 自适应扳机

> 用预设或自定义区段，设置 DualSense 自适应扳机的阻力，以及 Xbox 扳机马达效果。

Source: https://gamepadly.com/sdk/zh/guides/adaptive-triggers

DualSense 的扳机可以在玩家扣动时产生阻力、段落感或振动。它们需要 [L1 WebHID 连接](https://gamepadly.com/sdk/zh/start/tiers#l1webhid点一次授权桌面版-chrome--edge)。在其他手柄上这些调用什么都不做，所以可以不加判断直接调用。

## 预设

```ts
p1.triggers.applyPreset('weapon', 'right'); // side：'left' | 'right' | 'both'（默认 'both'）
p1.triggers.applyPreset('off');
```

| 预设 | 效果 |
| :--- | :--- |
| `'weapon'` | 一道会被压穿的阻力墙，像枪的扳机 |
| `'heavy_weapon'` | 更靠后、更硬的阻力墙 |
| `'bow'` | 越拉阻力越大 |
| `'abs'` | 扣过某个位置后振动，像 ABS 刹车 |
| `'soft_wall'` | 从中段开始的轻柔恒定阻力 |
| `'rapid_pulse'` | 几乎整个行程都快速振动 |
| `'precision_damp'` | 便于精细控制的轻阻力 |
| `'off'` | 无效果 |

## 自定义效果

```ts
p1.triggers.setRight({ type: 'weapon', startZone: 2, endZone: 5, strength: 7 });
p1.triggers.setLeft({ type: 'slope', startZone: 1, endZone: 8, startStrength: 1, endStrength: 7 });
p1.triggers.setBoth({ type: 'feedback', startZone: 4, strength: 4 }, { type: 'off' });
```

扳机行程分成 `0`（松开）到 `9`（按到底）的区段。强度范围是 `1` 到 `8`。

| 类型 | 字段 | 行为 |
| :--- | :--- | :--- |
| `'feedback'` | `startZone`、`strength` | 从 `startZone` 到底的恒定阻力 |
| `'slope'` | `startZone`、`endZone`、`startStrength`、`endStrength` | 在两个区段之间渐变的阻力 |
| `'weapon'` | `startZone`、`endZone`、`strength` | 两个区段之间的一道墙，压过去时会突然松开 |
| `'vibration'` | `startZone`、`amplitude`、`frequencyHz` | 从 `startZone` 开始振动 |
| `'off'` | | 释放扳机 |

## 在合适的时机应用效果

扳机效果只有在 WebHID 连接后才会到达手柄，所以在能力变化时要重新设置：

```ts
const syncTriggers = () => p1.triggers.applyPreset('weapon', 'right');
syncTriggers();
hub.onCapabilitiesChange(syncTriggers);
```

离开使用扳机效果的模式时，用 `p1.triggers.reset()` 复位。`hub.dispose()` 和页面退出会自动复位所有手柄。

## Xbox 扳机马达

Xbox Series 手柄的每个扳机里都有小马达。Chrome 和 Edge 不需要 WebHID 就能使用它们：

```ts
p1.triggers.pulseImpulse({ left: 0, right: 0.8, durationMs: 80 });
```

当扳机马达是最好的可用输出时，触觉预设已经会用上它们。
