@@ -123,10 +123,10 @@ const meta = {
123123</BaseLayout >
124124<script >
125125 enum ArrowKeys {
126- LEFT = 37 ,
127- UP = 38 ,
128- RIGHT = 39 ,
129- DOWN = 40
126+ LEFT = "ArrowLeft" ,
127+ UP = "ArrowUp" ,
128+ RIGHT = "ArrowRight" ,
129+ DOWN = "ArrowDown"
130130 }
131131
132132 enum ContentType {
@@ -171,8 +171,8 @@ const meta = {
171171
172172 #emitEvent() {
173173 document.addEventListener("keyup", (e: KeyboardEvent) => {
174- const { charCode, code, keyCode, key } = e;
175- this.onKeyChange(keyCode );
174+ const { key } = e;
175+ this.onKeyChange(key );
176176 });
177177
178178 this.#orientationPanel.forEach((radio) => {
@@ -328,12 +328,12 @@ const meta = {
328328 this.#panel.style.transform = transformString;
329329 }
330330
331- onKeyChange(code: number ) {
331+ onKeyChange(key: string ) {
332332 const VerticalButton = this.#orientationPanel[0] as HTMLInputElement;
333333 const horizontalButton = this.#orientationPanel[1] as HTMLInputElement;
334334 const currentPanelSize = Number(this.#cellRange.value);
335335
336- switch (code ) {
336+ switch (key ) {
337337 case ArrowKeys.RIGHT: {
338338 if (this.#orientation === "Y") {
339339 this.#selectedIndex--;
@@ -368,22 +368,23 @@ const meta = {
368368 }
369369 default: {
370370 // Handle character input (alphabets and numbers)
371+ const char = key.toUpperCase();
371372 if (this.#contentType === ContentType.ALPHABET) {
372- if (code >= 65 && code <= 90 ) {
373+ if (/^[A-Z]$/.test(key) ) {
373374 // A-Z (uppercase)
374- this.#selectedIndex = (65 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to A
375- } else if (code >= 97 && code <= 122 ) {
375+ this.#selectedIndex = (65 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to A
376+ } else if (/^[a-z]$/.test(key) ) {
376377 // a-z (lowercase)
377- this.#selectedIndex = (97 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to a
378+ this.#selectedIndex = (97 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to a
378379 } else {
379380 // If not an alphabet, just move forward
380381 this.#selectedIndex++;
381382 }
382383 } else {
383384 // ContentType.NUMBERS
384- if (code >= 48 && code <= 57 ) {
385+ if (/^[0-9]$/.test(key) ) {
385386 // 0-9
386- this.#selectedIndex = (48 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to 0
387+ this.#selectedIndex = (48 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to 0
387388 } else {
388389 // If not a number, just move forward
389390 this.#selectedIndex++;
0 commit comments