---
title: useKeypress
description: "Subscribes to normalized global keydown events."
---

```tsx
import { useKeypress } from 'filedom';

const { lastKey } = useKeypress({
  onKey: (key) => {
    if (key === 'r') restart();
  },
});
```

Arrow keys arrive as `up`, `down`, `left` and `right`, Return as `enter` and Space as `space`. Other keys arrive as their lowercased character. The listener only reports keydowns, so there is no keyup or held-key state.

## Options

| Prop | Type | Default | Description |
| - | - | - | - |
| `disableTerminalEcho?` | `boolean` | - | Turn off terminal echo while mounted and turn it back on at unmount. |
| `onKey?` | `((key: string, event: GlobalInputEvent) => void)` | - | Receives the normalized key and the raw GlobalInputEvent. Not called for keys with no name, such as a bare modifier. |

## Returns

`{ lastKey: string | null, lastEvent: GlobalInputEvent | null }`. Both start as null, and `lastKey` is null after a key with no name.
