DOM

インターフェイス

Window:keydown イベント

 編集:2022.10.18 by T.A.

[Edge]。→mdnmdn(en-US)

ウインドウ内でキーが押されたときに発行されます。シフト キーなどの装飾キーも発行されます。

バブリング ¶あり
キャンセル可能 ¶はい
インターフェイス KeyboardEvent
イベント ハンドラー プロパティ onkeydown

→Element:keydown イベント

keydown イベント

HTML:

<SPAN contenteditable>[SPAN要素。ここで編集…]</SPAN><BR>
<INPUT type=text>
<SPAN id=IdLog></SPAN>

JavaScript:

function Job(eve){  //keydown イベントの処理:
  D=eve;  //=[object]:[object KeyboardEvent]。「JavaScript:」をクリックしてから [a]キーを押した。
詳細 //isTrusted=[boolean]:true //key=[string]:a //code=[string]:KeyA //location=[number]:0 //ctrlKey=[boolean]:false //shiftKey=[boolean]:false //altKey=[boolean]:false //metaKey=[boolean]:false //repeat=[boolean]:false //isComposing=[boolean]:false //charCode=[number]:0 //keyCode=[number]:65 //DOM_KEY_LOCATION_STANDARD=[number]:0 //DOM_KEY_LOCATION_LEFT=[number]:1 //DOM_KEY_LOCATION_RIGHT=[number]:2 //DOM_KEY_LOCATION_NUMPAD=[number]:3 //getModifierState=[function]:function getModifierState() { [native code] } //initKeyboardEvent=[function]:function initKeyboardEvent() { [native code] } //view=[object]:[object Window] //detail=[number]:0 //sourceCapabilities=[object]:[object InputDeviceCapabilities] //which=[number]:65 //initUIEvent=[function]:function initUIEvent() { [native code] } //type=[string]:keydown //target=[object]:[object HTMLBodyElement] //currentTarget=[object]:null //eventPhase=[number]:0 //bubbles=[boolean]:true //cancelable=[boolean]:true //defaultPrevented=[boolean]:false //composed=[boolean]:true //…
IdLog.innerHTML="key:"+eve.key+"<BR>" } window.onkeydown=Job; //イベント割り当て。

どの要素上でもイベントが起こるようです。

編集可能要素で FEP を介して「あ」の [a]キーを押した。

//D=[object]:[object KeyboardEvent]
詳細//isTrusted=[boolean]:true //key=[string]:Process //code=[string]:KeyA //location=[number]:0 //ctrlKey=[boolean]:false //shiftKey=[boolean]:false //altKey=[boolean]:false //metaKey=[boolean]:false //repeat=[boolean]:false //isComposing=[boolean]:false //charCode=[number]:0 //keyCode=[number]:229 //DOM_KEY_LOCATION_STANDARD=[number]:0 //DOM_KEY_LOCATION_LEFT=[number]:1 //DOM_KEY_LOCATION_RIGHT=[number]:2 //DOM_KEY_LOCATION_NUMPAD=[number]:3 //getModifierState=[function]:function getModifierState() { [native code] } //initKeyboardEvent=[function]:function initKeyboardEvent() { [native code] } //view=[object]:[object Window] //detail=[number]:0 //sourceCapabilities=[object]:[object InputDeviceCapabilities] //which=[number]:229 //initUIEvent=[function]:function initUIEvent() { [native code] } //type=[string]:keydown //target=[object]:[object HTMLSpanElement] //currentTarget=[object]:null //eventPhase=[number]:0 //bubbles=[boolean]:true //cancelable=[boolean]:true //defaultPrevented=[boolean]:false //composed=[boolean]:true //…

[Shift]キーを押した時。 //D=[object]:[object KeyboardEvent]

詳細//isTrusted=[boolean]:true //key=[string]:Shift //code=[string]:ShiftLeft //location=[number]:1 //ctrlKey=[boolean]:false //shiftKey=[boolean]:true //altKey=[boolean]:false //metaKey=[boolean]:false //repeat=[boolean]:true //isComposing=[boolean]:false //charCode=[number]:0 //keyCode=[number]:16 //DOM_KEY_LOCATION_STANDARD=[number]:0 //DOM_KEY_LOCATION_LEFT=[number]:1 //DOM_KEY_LOCATION_RIGHT=[number]:2 //DOM_KEY_LOCATION_NUMPAD=[number]:3 //getModifierState=[function]:function getModifierState() { [native code] } //initKeyboardEvent=[function]:function initKeyboardEvent() { [native code] } //view=[object]:[object Window] //detail=[number]:0 //sourceCapabilities=[object]:[object InputDeviceCapabilities] //which=[number]:16 //initUIEvent=[function]:function initUIEvent() { [native code] } //type=[string]:keydown //target=[object]:[object HTMLButtonElement] //currentTarget=[object]:null //eventPhase=[number]:0 //bubbles=[boolean]:true //cancelable=[boolean]:true //defaultPrevented=[boolean]:false //composed=[boolean]:true //…

テスト
HTML:


ここにHTMLが表示される
スクリプト組み込み:
JavaScript:


JavaScript:



表示内容:
表示内容: