diff --git a/apps/frontend/src/components/keyboard-shortcuts.tsx b/apps/frontend/src/components/keyboard-shortcuts.tsx index 2b89689..8d0775f 100644 --- a/apps/frontend/src/components/keyboard-shortcuts.tsx +++ b/apps/frontend/src/components/keyboard-shortcuts.tsx @@ -7,7 +7,7 @@ export default function KeyboardShortcuts() { const router = useRouter(); useEffect(() => { - function handleKeyDown(event: KeyboardEvent) { + function handleAddKeyDown(event: KeyboardEvent) { // input, textarea, contenteditable에서는 무시 const target = event.target as HTMLElement; if ( @@ -23,8 +23,29 @@ export default function KeyboardShortcuts() { } } - document.addEventListener("keydown", handleKeyDown); - return () => document.removeEventListener("keydown", handleKeyDown); + document.addEventListener("keydown", handleAddKeyDown); + return () => document.removeEventListener("keydown", handleAddKeyDown); + }, [router]); + + useEffect(() => { + function handleHomeKeyDown(event: KeyboardEvent) { + // input, textarea, contenteditable에서는 무시 + const target = event.target as HTMLElement; + if ( + target.tagName === "INPUT" || + target.tagName === "TEXTAREA" || + target.isContentEditable + ) { + return; + } + + if (event.key === "h" || event.key === "H") { + router.push("/"); + } + } + + document.addEventListener("keydown", handleHomeKeyDown); + return () => document.removeEventListener("keydown", handleHomeKeyDown); }, [router]); return null;