'use strict';

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

var React = require('react');

function useKeyPress(targetKey, ref) {
    const [keyPressed, setKeyPressed] = React.useState(false);
    function downHandler(event) {
        const { code } = event;
        if (code === targetKey) {
            setKeyPressed(true);
            event.preventDefault();
        }
    }
    const upHandler = (event) => {
        const { code } = event;
        if (code === targetKey) {
            setKeyPressed(false);
            event.preventDefault();
        }
    };
    React.useEffect(() => {
        var _a, _b;
        (_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('keydown', downHandler);
        (_b = ref.current) === null || _b === void 0 ? void 0 : _b.addEventListener('keyup', upHandler);
        return () => {
            var _a, _b;
            (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('keydown', downHandler);
            (_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('keyup', upHandler);
        };
    }, [downHandler, upHandler]);
    return keyPressed;
}

exports.useKeyPress = useKeyPress;
