keydown(onkeydown) イベント
KeyboardEvent
keydown ( onkeydown ) イベントは、キーボードのキーを押すと発生する KeyboardEvent インターフェイスのイベントです。 キーボード入力が許可された input 、textarea などの form エレメントが対象です。
全てのキーに反応します。
document.getElementById('example').addEventListener("keydown", (event)=>{ console.log( 'event type : ' + event.type ); });
formエレメント以外のエレメントにKeybordイベントを設定するには、Keyboardイベント「formエレメント以外のKeyboadイベントの設定」を参照して下さい。
押されたキーを取得するには、event.key 、 event.code プロパティなどを使用します。詳しくは KeyboardEvent インターフェイスのプロパティを参照してください。
構文(Syntax)
in HTML
<tagelement onkeydown="function()">
in JavaScript
object.onkeydown = function(){ }; object.addEventListener("keydown", script_);
備考(Remarks)
Bubbles | Yes |
Cancelable | Yes |
Interface | KeyboardEvent |
Supported HTML Elements | ALL HTML elements |
Example
関連(Related)
HTML、CSS、DOMのマウス、キーボード、タッチデバイス、カーソルに関する用途一覧です。
HTML
CSS
DOM
- 全般
-
- インターフェイス
- UiEvent
- イベント
- which
- プロパティ
- altKey、 ctrlKey、 metaKey、 relatedTarget、 shiftKey
- メソッド
- getModifierState()
- マウス
-
- インターフェイス
- DragEvent、 MouseEvent
- イベント
- click、 contextmenu、 dblclick、 dragend、 dragenter、 dragleave、 dragover、 dragstart、 drop、 mousedown、 mouseenter、 mouseleave、 mousemove、 mouseout、 mouseover、 mouseup、 show、 onwheel
- プロパティ
- button、 buttons、 clientX、 clientY、 code、 deltaMode、 deltaX、 deltaY、 deltaZ、 pageX、 pageY、 screenX、 screenY
- メソッド
- キーボード
- タッチデバイス
-
- インターフェイス
- TouchEvent
- イベント
- touchcancel、 touchend、 touchmove、 touchstart、 transitionend
- プロパティ
- メソッド