diff --git a/theatre/studio/src/uiComponents/useKeyDownCallback.tsx b/theatre/studio/src/uiComponents/useKeyDownCallback.tsx index 0fd4bb7..b29a892 100644 --- a/theatre/studio/src/uiComponents/useKeyDownCallback.tsx +++ b/theatre/studio/src/uiComponents/useKeyDownCallback.tsx @@ -4,7 +4,7 @@ type AcceptableCombo = 'Shift' | 'Meta' | 'Control' | 'Alt' export default function useKeyDownCallback( combo: AcceptableCombo, - listener: (opts: {down: boolean; event: KeyboardEvent}) => void, + listener: (opts: {down: boolean; event: KeyboardEvent | undefined}) => void, ) { const refs = useRef({combo, listener}) refs.current = {combo, listener} @@ -21,11 +21,17 @@ export default function useKeyDownCallback( } } + function onBlur(event: unknown) { + refs.current.listener({down: false, event: undefined}) + } + document.addEventListener('keydown', onKeyDown) document.addEventListener('keyup', onKeyUp) + window.addEventListener('blur', onBlur) return () => { document.removeEventListener('keydown', onKeyDown) document.removeEventListener('keyup', onKeyUp) + window.removeEventListener('blur', onBlur) } }, []) }