hotKeyAction

An action to add a keyboard shortcut to a div or a button.

Demo

Clicked: 0

Clicked: 0

Usage

<script>
  import { hotKeyAction } from "svelte-legos";

  let timesClicked = 0;
  let timesClickedCallback = 0;
</script>

<button
  use:hotKeyAction={{ shift: true, code: 'Digit1' }}
  on:click={() => timesClicked++}
>
  Triggers a click on Shift + 1
</button>
<p>
  Clicked: {timesClicked}
</p>

<div
  use:hotKeyAction={{ shift: true, meta: true, code: 'KeyX', cb: () => timesClickedCallback++ }}
>
  Triggers a callback on Shift + Cmd + X
</div>
<p>
  Clicked: {timesClickedCallback}
</p>