Skip to content

Commit 43545ca

Browse files
authored
Support Arrow Left-Rigth key controls (#8)
1 parent 504c9b8 commit 43545ca

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/app/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ const App: FC = () => {
8787

8888
return (): void => window.removeEventListener('wheel', wheelListener);
8989
}, [wheelListener]);
90+
91+
const keyboardListener = useCallback((event: KeyboardEvent): void => {
92+
const currentSectionIndex = currentSectionIndexRef.current;
93+
94+
95+
if (event.key === 'ArrowLeft' && currentSectionIndex !== 0) {
96+
updateSectionIndex(currentSectionIndex - 1);
97+
return;
98+
}
99+
100+
if (event.key === 'ArrowRight' && currentSectionIndex !== Sections.length - 1) {
101+
updateSectionIndex(currentSectionIndex + 1);
102+
}
103+
}, []);
104+
105+
useEffect(() => {
106+
window.addEventListener('keydown', keyboardListener);
107+
108+
return (): void => window.removeEventListener('keydown', keyboardListener);
109+
}, [keyboardListener]);
90110

91111
const touchStartTimeRef = useRef<number>(Date.now());
92112
const touchStartRef = useRef<[number, number]>([0, 0]);

0 commit comments

Comments
 (0)