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.
import { nycklar } from "nycklar";
nycklar(window, {
"Shift+D": () => {
console.log("pressed shift and d");
},
abc: () => {
console.log("pressed the abc keys in order");
},
});
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();
};
});
};