KeyboardEvent()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
KeyboardEvent() constructor 能用來建立一個新的 KeyboardEvent。
語法
event = new KeyboardEvent(typeArg, KeyboardEventInit);
參數
type-
一
DOMString用來表示事件名稱。 options選擇性-
一個
KeyboardEventInitdictionary,能接受以下參數:key選擇性-
一個字符串,默認值為
"",用來設定KeyboardEvent.key的值。 code選擇性-
一個字符串,默認值為
"",用來設定KeyboardEvent.code的值。 location選擇性-
一個
unsigned long,默認值為0,用來設定KeyboardEvent.location的值。 ctrlKey選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.ctrlKey的值。 shiftKey選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.shiftKey的值。 altKey選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.altKey的值。 metaKey選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.metaKey的值。 repeat選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.repeat的值。 isComposing選擇性-
一個
Boolean,默認值為false,用來設定KeyboardEvent.isComposing的值。 charCode選擇性-
一個
unsigned long,默認值為0,用來設定KeyboardEvent.charCode的值。 keyCode選擇性-
一個
unsigned long,默認值為0,用來設定KeyboardEvent.keyCode的值。 which選擇性-
一個
unsigned long,默認值為0,用來設定KeyboardEvent.which的值
備註:KeyboardEventInit dictionary 亦接受 UIEventInit 和EventInit 所接受的參數。
規格
| Specification |
|---|
| UI Events> # dom-keyboardevent-keyboardevent> |
瀏覽器支援度
延伸閱讀
KeyboardEvent,此 constructer 所建立的 object 的 interface