Skip to content

kwaimind/nycklar

Repository files navigation

🔑 nycklar

A tiny proptype for keybindings, inspired by the tinykeys lib

This is a tiny version of what tinykeys can do, and is more of a personal project than something you should use.

Usage

import { nycklar } from "nycklar";

nycklar(window, {
  "Shift+D": () => {
    console.log("pressed shift and d");
  },
  abc: () => {
    console.log("pressed the abc keys in order");
  },
});

React Hooks Example

If you're using nycklar within a component, you should also make use of the returned cleanup() function.

import { useEffect } from "react";
import { nycklar } from "nycklar";

const myKeybindingsHook = () => {
  useEffect(() => {
    let cleanup = nycklar(window, {
      // ...
    });
    return () => {
      cleanup();
    };
  });
};

About

A basic prototype of the tinykeys lib

Topics

Resources

Stars

Watchers

Forks