fix(web/skillcheck) fix cyrillic keyboards not detecting correct inputs (#512)

resolves #410
This commit is contained in:
qwezertino
2024-03-09 12:06:06 +02:00
committed by GitHub
parent d8578281ee
commit 669dc5ae87

View File

@@ -21,10 +21,21 @@ const Indicator: React.FC<Props> = ({ 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]
);