'use strict';

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

var React = require('react');

function useWindowKeyPress(targetKey) {
    const [keyPressed, setKeyPressed] = React.useState(false);
    function downHandler(event) {
        const { code } = event;
        if (code === targetKey) {
            setKeyPressed(true);
        }
    }
    const upHandler = (event) => {
        const { code } = event;
        if (code === targetKey) {
            setKeyPressed(false);
        }
    };
    React.useEffect(() => {
        window.addEventListener('keydown', downHandler);
        window.addEventListener('keyup', upHandler);
        return () => {
            window.removeEventListener('keydown', downHandler);
            window.removeEventListener('keyup', upHandler);
        };
    }, [downHandler, upHandler]);
    return keyPressed;
}

exports.useWindowKeyPress = useWindowKeyPress;
