KeyboardEvent()
constructor 能用來建立一個新的 KeyboardEvent
。
語法
event = new KeyboardEvent(typeArg, KeyboardEventInit);
參數
- typeArg
- 一
DOMString
用來表示事件名稱。 - KeyboardEventInit選擇性
- 一個
KeyboardEventInit
dictionary,能接受以下參數:參數 可選 默認值 類型 說明 "key"
● ""
DOMString
用來設定 KeyboardEvent.key
的值"code"
● ""
DOMString
用來設定 KeyboardEvent.code
的值"location"
● 0 unsigned long
用來設定 KeyboardEvent.location
的值"ctrlKey"
● false
Boolean
用來設定 KeyboardEvent.ctrlKey
的值"shiftKey"
● false
Boolean
用來設定 KeyboardEvent.shiftKey
的值"altKey" ● false
Boolean
用來設定 KeyboardEvent.altKey
的值"metaKey" ● false
Boolean
用來設定 KeyboardEvent.metaKey
的值"repeat" ● false
Boolean
用來設定 KeyboardEvent.repeat
的值"isComposing" ● false
Boolean
用來設定 KeyboardEvent.isComposing
的值"charCode" ● 0 unsigned long
用來設定 KeyboardEvent.charCode
的值"keyCode" ● 0 unsigned long
用來設定 KeyboardEvent.keyCode
的值"which" ● 0 unsigned long
用來設定 KeyboardEvent.which
的值KeyboardEventInit
dictionary 亦接受UIEventInit
和EventInit
所接受的參數。
規格
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Events Specification The definition of 'KeyboardEvent()' in that specification. |
Obsolete | Initial definition. |
瀏覽器支援度
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 13 (13) | No support | (Yes) | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | (Yes) | 31.0 (31) | No support | (Yes) | ? | (Yes) |
延伸閱讀
KeyboardEvent
,此 constructer 所建立的 object 的 interface