# svelte-hotkey

> A simple keyboard shortcut action for Svelte 5

Latest version **1.0.0** (published 2025-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install svelte-hotkey
pnpm add svelte-hotkey
yarn add svelte-hotkey
bun add svelte-hotkey
```

## Health

**Score 45/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2025-04-04 |
| First published | 2023-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Oleg Sedinkin |
| Maintainers | akeylimepie |
| Keywords | svelte, hotkey |

## Links

- npm: https://www.npmjs.com/package/svelte-hotkey
- Repository: https://github.com/akeylimepie/svelte-hotkey
- Homepage: https://github.com/akeylimepie/svelte-hotkey#readme
- Issues: https://github.com/akeylimepie/svelte-hotkey/issues
- npm.io page: https://npm.io/package/svelte-hotkey

## Recent versions

- 1.0.0 (latest) — 2025-04-04
- 0.0.4 — 2025-04-01
- 0.0.3 — 2023-09-27
- 0.0.2 — 2023-09-26
- 0.0.1 — 2023-09-26

## README

# svelte-hotkey

A simple keyboard shortcut action for Svelte 5.

---

## Install

```bash
npm install svelte-hotkey
```

---

## Usage

```svelte
<script lang="ts">
	import { hotkey } from 'svelte-hotkey';

	function showCommandPalette() {
		console.log('Open command palette');
	}
</script>

<button use:hotkey={{ ctrlKey: true, code: 'KeyK', handle: showCommandPalette }}>
	Ctrl + K
</button>
```

Pressing `Ctrl + K` triggers the `showCommandPalette` function.

When `handle` is omitted, clicking the element is used as the default behavior.

```svelte
<button
	use:hotkey={{ shiftKey: true, code: 'Enter'  }}>
	Send
</button>
```

---

## Parameters

| Name          | Type                      | Description                                                                                                                         |
|---------------|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `code`        | `string`                  | The [`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code) to match (e.g. `'KeyS'`, `'Enter'`) |
| `ctrlKey`     | `boolean` _(optional)_    | Require the Ctrl key                                                                                                                |
| `metaKey`     | `boolean` _(optional)_    | Require the Meta key                                                                                                                |
| `shiftKey`    | `boolean` _(optional)_    | Require the Shift key                                                                                                               |
| `altKey`      | `boolean` _(optional)_    | Require the Alt key                                                                                                                 |
| `handle`      | `() => void` _(optional)_ | Custom handler function                                                                                                             |
| `allowRepeat` | `boolean` _(optional)_    | Allow repeated key events (default: `false`)                                                                                        |

---

## License

MIT

---
_Source: https://npm.io/package/svelte-hotkey · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
