'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');

function useKey(key, callback, propsThatChange) {
  const [pressed, setPressed] = React.useState(false);
  React.useEffect(() => {
    const match = (event) => event.key && key.constructor === String ? key.toLowerCase() === event.key.toLowerCase() : false;
    const onDown = (event) => {
      if (match(event))
        setPressed(true);
    };
    const onUp = (event) => {
      if (match(event)) {
        setPressed(false);
        if (callback)
          callback();
      }
    };
    window.addEventListener("keydown", onDown);
    window.addEventListener("keyup", onUp);
    return () => {
      window.removeEventListener("keydown", onDown);
      window.removeEventListener("keyup", onUp);
    };
  }, [key, propsThatChange, callback]);
  return pressed;
}

exports["default"] = useKey;
exports.useKey = useKey;
//# sourceMappingURL=useKey.cjs.map
