[index.js] convert keyboard numeric keystroke values

Detail Notes :

1. if the KeyboardEvent doesn't have a 'key' option,
2. in the keyDown event,
3. in the keyboard input is in the range 0-9,
4. returns the number corresponding to event.key
This commit is contained in:
jaeyeonee
2024-02-20 13:53:55 +09:00
parent 1071b87d75
commit 3ed8fd1331

View File

@@ -42,6 +42,25 @@ if (typeof window === "object") {
document.addEventListener("keyup", getFalseOnRepeat, true);
}
// Adding the 'key' option to KeyboardEvent in webOS3.0
if (!("key" in window.KeyboardEvent.prototype)) {
const getKeyOption = (event) => {
console.log(
"KeyDown Event / This browser does not have a 'key' value for KeyboardEvent"
);
if (event.keyCode >= 48 && event.keyCode <= 57) {
Object.defineProperty(event, "key", {
get: function () {
return this.keyCode - 48;
},
});
}
};
document.addEventListener("keydown", getKeyOption, true);
}
window.store = store;
render(appElement, document.getElementById("root"));