Fix IME input

main
Elnu 2 years ago
parent d0fa263a38
commit c92f3e82ac

@ -76,8 +76,7 @@ function convertKeyCode(evt) {
if (keyCode == 88)
chara = (shift) ? "X" : "x";
if (keyCode == 89)
chara = (shift) ? "Y" : "y";
if (keyCode == 90)
chara = (shift) ? "Y" : "y"; if (keyCode == 90)
chara = (shift) ? "Z" : "z";
if (keyCode == 93)
chara = "select key";
@ -114,7 +113,6 @@ const leftShiftCode = 32; // space
const rightShiftCode = 16; // shift key
let leftShift = false;
let rightShift = false;
let inComposition = false;
addEventListener("keydown", event => {
switch(event.keyCode) {
case leftShiftCode:
@ -137,12 +135,19 @@ addEventListener("keyup", event => {
break;
}
});
addEventListener("compositionstart", event => inComposition = true);
addEventListener("compositionend", event => inComposition = false);
input.addEventListener("keydown", e => {
if (inComposition) {
return;
const check = () => {
if (input.value == word) {
clearTimeout(timeout);
wordDisplay.style.color = "green";
wordDisplay.innerHTML += " ✅";
setTimeout(() => {
wordDisplay.style.color = "";
reset();
}, 1000);
}
};
addEventListener("compositionend", event => check());
input.addEventListener("keydown", e => {
const pressed = convertKeyCode(e).toLowerCase(); // String.fromCharCode(e.keyCode).toLowerCase();
if (keymap[pressed] !== undefined) {
let valueIndex = 0;
@ -152,15 +157,7 @@ input.addEventListener("keydown", e => {
valueIndex = 2;
}
input.value += keymap[pressed][valueIndex];
if (input.value == word) {
clearTimeout(timeout);
wordDisplay.style.color = "green";
wordDisplay.innerHTML += " ✅";
setTimeout(() => {
wordDisplay.style.color = "";
reset();
}, 1000);
}
check();
e.preventDefault();
} else if (pressed == " ") {
e.preventDefault();