Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

svelte-hotkeys

puruvj17MIT0.1.1TypeScript support: included

Svelte wrapper around hotkeys-js

svelte, keyboard, hotkeys, hotkeys-js, actions, hooks, svelte-actions

readme

Docs coming soon!

Meanwhile, basic usage:

import { hotkeys } from "svelte-hotkeys";

Later in svelte component

<svelte:window use:hotkeys={{ keys: 'ctrl+x', handler: (ev) => console.log(ev) }} />

This binds hotkeys to the window, as in hitting the key anywhere will trigger the handler

if you wanna make hotkeys specific to a specific element, as in, if a div is in focus and user hits the key combo, the handler should be triggered. This can be done by applying this action on a focusable div

<div tabindex={0} use:hotkeys={{ keys: 'ctrl+x', handler: (ev) => console.log(ev) }} />