Tiny Key Binding JavaScript Library – Tinykeys.js

Category: Javascript , Recommended | July 31, 2020
Author: jamiebuilds
Views Total: 28 views
Official Page: Go to website
Last Update: July 31, 2020
License: MIT

Preview:

Tiny Key Binding JavaScript Library – Tinykeys.js

Description:

A super tiny (~0.4kb) JavaScript library for handling key bindings on the web app.

How to use it:

1. Install & download.

# NPM
$ npm i tinykeys --save

2. Import the Tinykeys.js.

# ES Module
import tinykeys from "tinykeys"

# Browser
<script src="https://cdn.jsdelivr.net/npm/tinykeys/dist/tinykeys.umd.js"></script>

3. Add keyboard shortcuts for actions in your web app.

tinykeys(window, {
  "Shift+D": () => {
    alert("The 'Shift' and 'd' keys were pressed at the same time")
  },
  "y e e t": () => {
    alert("The keys 'y', 'e', 'e', and 't' were pressed in order")
  },
  "$mod+KeyD": () => {
    alert("Either 'Control+d' or 'Meta+d' were pressed")
  },
})

You Might Be Interested In:


Leave a Reply