import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
// Hook
function useKey(key, callback, propsThatChange) {
    // Keep track of key state
    const [pressed, setPressed] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    // Bind and unbind events
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        // Does an event match the key we're watching?
        const match = (event)=>!!event.key && key.constructor === String && key.toLowerCase() === event.key.toLowerCase();
        // Event handlers
        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;
}
/* ESM default export */ const useKey_rslib_entry_ = useKey;
export { useKey_rslib_entry_ as default, useKey };
