Keyboardイベント
4333 ワード
キーボードイベントを参照
So, event.code
may match a wrong character for unexpected layout. Same letters in different layouts may map to different physical keys, leading to different codes. Luckily, that happens only with several codes, e.g. keyA
, keyQ
, keyZ
(as we’ve seen), and doesn’t happen with special keys such as Shift
. You can find the list in the
英語を使う国のキーボードとドイツのキーボードのレイアウトが違うのでevent.コード値は同じですが、イベントです.key値が異なる現象が発生します.
event.code値自体は、英米のキーボードレイアウトに関連付けられています.
Preventing the default action on keydown
can cancel most of them, with the exception of OS-based special keys. For instance, on Windows Alt+F4 closes the current browser window. And there’s no way to stop it by preventing the default action in JavaScript.
OSベースのキーオフイベントはeventです.防ぎきれない
event.重要な例
switch (event.key) {
case "Down": // IE/Edge specific value
case "ArrowDown":
// Do something for "down arrow" key press.
break;
case "Up": // IE/Edge specific value
case "ArrowUp":
// Do something for "up arrow" key press.
break;
case "Left": // IE/Edge specific value
case "ArrowLeft":
// Do something for "left arrow" key press.
break;
case "Right": // IE/Edge specific value
case "ArrowRight":
// Do something for "right arrow" key press.
break;
case "Enter":
// Do something for "enter" or "return" key press.
break;
case "Esc": // IE/Edge specific value
case "Escape":
// Do something for "esc" key press.
break;
default:
return; // Quit when this doesn't handle the key event.
}
Reference
この問題について(Keyboardイベント), 我々は、より多くの情報をここで見つけました
https://velog.io/@hqillz/Keyboard-이벤트
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
switch (event.key) {
case "Down": // IE/Edge specific value
case "ArrowDown":
// Do something for "down arrow" key press.
break;
case "Up": // IE/Edge specific value
case "ArrowUp":
// Do something for "up arrow" key press.
break;
case "Left": // IE/Edge specific value
case "ArrowLeft":
// Do something for "left arrow" key press.
break;
case "Right": // IE/Edge specific value
case "ArrowRight":
// Do something for "right arrow" key press.
break;
case "Enter":
// Do something for "enter" or "return" key press.
break;
case "Esc": // IE/Edge specific value
case "Escape":
// Do something for "esc" key press.
break;
default:
return; // Quit when this doesn't handle the key event.
}
Reference
この問題について(Keyboardイベント), 我々は、より多くの情報をここで見つけました https://velog.io/@hqillz/Keyboard-이벤트テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol