[Edge]○。→、
新しい KeyboardEvent オブジェクトを作成して返します。
| type | イベントの名前を表す文字列。大文字と小文字の区別される。ブラウザーでは keydown、keyup、keypress の何れかに設定します。
| ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options | 省略可。オブジェクト。UIEvent() で定義されているものに加え、以下のプロパティを持つことができます。
|
新しい KeyboardEvent オブジェクト。
HTML:
<SPAN id=IdTest contenteditable>[SPAN要素。ここで編集操作…]</SPAN><BR> <SPAN id=IdLog></SPAN>
JavaScript:
function Job(eve){ //keydown イベントの処理:
D=eve; //=[object]:[object KeyboardEvent]。スクリプトによりイベントを発生させた。
詳細
//isTrusted=[boolean]:false
//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]:0
//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]:null
//detail=[number]:0
//sourceCapabilities=[object]:null
//which=[number]:0
//initUIEvent=[function]:function initUIEvent() { [native code] }
//type=[string]:keydown
//target=[object]:[object HTMLSpanElement]
//currentTarget=[object]:null
//eventPhase=[number]:0
//bubbles=[boolean]:false
//cancelable=[boolean]:false
//defaultPrevented=[boolean]:false
//composed=[boolean]:false
//…
IdLog.innerHTML=IdLog.innerHTML+"●"; //表示。
}
IdTest.onkeydown=Job; //イベント割り当て。
Ev=new KeyboardEvent('keydown', {key:'a', code:'KeyA'}); //イベント生成。
IdTest.dispatchEvent(Ev); //イベントを起こす。
スクリプトでイベントを発生させても、起きた要素内容には何も影響はないようです。
SPAN要素で [a] キーを押した場合に発生したイベントで得た内容
//D=[object]:[object KeyboardEvent]詳細
//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 HTMLSpanElement] //currentTarget=[object]:null //eventPhase=[number]:0 //bubbles=[boolean]:true //cancelable=[boolean]:true //defaultPrevented=[boolean]:false //composed=[boolean]:true //…