tinykeys

A tiny (~400 B) & modern library for keybindings.

npm install tinykeys

Examples

Try some of the following:

import tinykeys from "tinykeys"

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+KeyU": () => {
    alert("Either 'Control+u' or 'Meta+u' were pressed")
  },
})

Debugger

Typing will log details of the event that was fired

event.key event.code event.getModifierState(event.key) event.getModifierState(...) event.repeating event.composing event.location

Note: event.getModifierState(event.key) tests if the key pressed is considered a "modifier" key