> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# KeyEvent

APISummary
表示键盘事件，继承自 [`Event`](/next/zh/api/lynx-api/event/event.md)，用于描述用户与键盘的交互行为。每一个事件都描述了用户与一个按键，或按键与修饰键组合的一次交互。

## 实例属性

### key

```ts
key: string;
```

表示用户按下的物理按键的值。

### repeat

```ts
repeat: boolean;
```

`true` 表示按键被持续按住并自动重复触发。

### altKey

```ts
altKey: boolean;
```

`true` 表示事件发生时 Alt 键处于按下状态；在 macOS 中，对应 Option（`⌥`）键。

### ctrlKey

```ts
ctrlKey: boolean;
```

`true` 表示事件发生时 Ctrl 键处于按下状态。

### metaKey

```ts
metaKey: boolean;
```

`true` 表示事件发生时 Meta 键处于按下状态。在 macOS 中对应 Command（`⌘`）键，在 Windows 中对应 Windows 键。

### shiftKey

```ts
shiftKey: boolean;
```

`true` 表示事件发生时 Shift 键处于按下状态。

## KeyEvent 的类型

### keydown

表示一个按键被按下。

### keyup

表示一个按键被释放。

## 兼容性

**Compatibility Table**

**Query:** `lynx-api.event.KeyEvent`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/event/KeyEvent.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| KeyEvent | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| key | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| repeat | No | No | No | Yes (3.7) | Yes (3.7) | No |
| altKey | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| ctrlKey | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| metaKey | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| shiftKey | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| keydown | No | No | No | Yes (3.7) | Yes (3.7) | Yes |
| keyup | No | No | No | Yes (3.7) | Yes (3.7) | Yes |

**`repeat`**

- **Web — Not supported:** The Web event bridge does not copy the browser repeat field.

