From 6686126dc0d30322fa2536a83f0b0f903f28b822 Mon Sep 17 00:00:00 2001 From: bsu3338 Date: Sun, 3 Sep 2023 22:49:08 -0500 Subject: [PATCH] Update SpeechRecognition.tsx --- client/src/components/Input/SpeechRecognition.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/client/src/components/Input/SpeechRecognition.tsx b/client/src/components/Input/SpeechRecognition.tsx index 68f17a24f7..1935b3257e 100644 --- a/client/src/components/Input/SpeechRecognition.tsx +++ b/client/src/components/Input/SpeechRecognition.tsx @@ -1,4 +1,5 @@ import { useState, useEffect } from 'react'; +import hotkeys from 'hotkeys-js'; const useSpeechRecognition = (ask) => { const [isSpeechSupported, setIsSpeechSupported] = useState(false); @@ -66,21 +67,17 @@ const useSpeechRecognition = (ask) => { } }; - const handleKeyDown = (e) => { - if (e.shiftKey && e.altKey && e.key === 'L') { + useEffect(() => { + hotkeys('shift+alt+l', (event, handler) => { if (isSpeechSupported) { toggleListening(); } - } - }; - - useEffect(() => { - window.addEventListener('keydown', handleKeyDown); + }); return () => { - window.removeEventListener('keydown', handleKeyDown); + hotkeys.unbind('shift+alt+l'); }; - }); + }, [isSpeechSupported]); return { isSpeechSupported, isListening, text, toggleListening }; };