From 669dc5ae871a150ba7adf2aaec71293f08ea64c7 Mon Sep 17 00:00:00 2001 From: qwezertino Date: Sat, 9 Mar 2024 12:06:06 +0200 Subject: [PATCH] fix(web/skillcheck) fix cyrillic keyboards not detecting correct inputs (#512) resolves #410 --- web/src/features/skillcheck/indicator.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/features/skillcheck/indicator.tsx b/web/src/features/skillcheck/indicator.tsx index 2dc14c9..f961faa 100644 --- a/web/src/features/skillcheck/indicator.tsx +++ b/web/src/features/skillcheck/indicator.tsx @@ -21,10 +21,21 @@ const Indicator: React.FC = ({ angle, offset, multiplier, handleComplete, }), 1 ); - const keyHandler = useCallback( (e: KeyboardEvent) => { - setKeyPressed(e.key.toLowerCase()); + const capitalHetaCode = 880; + const isNonLatin = e.key.charCodeAt(0) >= capitalHetaCode; + var convKey = e.key.toLowerCase() + if (isNonLatin) { + if (e.code.indexOf('Key') === 0 && e.code.length === 4) { // i.e. 'KeyW' + convKey = e.code.charAt(3); + } + + if (e.code.indexOf('Digit') === 0 && e.code.length === 6) { // i.e. 'Digit7' + convKey = e.code.charAt(5); + } + } + setKeyPressed(convKey.toLowerCase()); }, [skillCheck] );