import { useState, useEffect } from "react";
function useKeyPressed(targetKey) {
  const [keyPressed, setKeyPressed] = useState(false);
  useEffect(() => {
    const downHandler = (event) => {
      if (event.key === targetKey || (event.metaKey || event.ctrlKey)) {
        setKeyPressed(true);
      }
    };
    const upHandler = (event) => {
      if (event.key === targetKey || !event.metaKey && !event.ctrlKey) {
        setKeyPressed(false);
      }
    };
    const blurHandler = () => {
      setKeyPressed(false);
    };
    window.addEventListener("keydown", downHandler);
    window.addEventListener("keyup", upHandler);
    window.addEventListener("blur", blurHandler);
    return () => {
      window.removeEventListener("keydown", downHandler);
      window.removeEventListener("keyup", upHandler);
      window.removeEventListener("blur", blurHandler);
    };
  }, [targetKey]);
  return keyPressed;
}
function useCmdOrCtrlPressed() {
  return useKeyPressed("Meta");
}
export {
  useCmdOrCtrlPressed,
  useKeyPressed
};
//# sourceMappingURL=use-key-pressed.js.map
