KeyboardEvent() constructor 能用來建立一個新的 KeyboardEvent


 event = new KeyboardEvent(typeArg, KeyboardEventInit);


DOMString 用來表示事件名稱。
一個 KeyboardEventInit dictionary,能接受以下參數:
參數 可選 默認值 類型 說明
"key" "" DOMString 用來設定 KeyboardEvent.key (en-US) 的值
"code" "" DOMString 用來設定 KeyboardEvent.code (en-US) 的值
"location" 0 unsigned long 用來設定 KeyboardEvent.location (en-US) 的值
"ctrlKey" false Boolean 用來設定 KeyboardEvent.ctrlKey (en-US) 的值
"shiftKey" false Boolean 用來設定 KeyboardEvent.shiftKey (en-US) 的值
"altKey" false Boolean 用來設定 KeyboardEvent.altKey (en-US) 的值
"metaKey" false Boolean 用來設定 KeyboardEvent.metaKey (en-US) 的值
"repeat" false Boolean 用來設定 KeyboardEvent.repeat (en-US) 的值
"isComposing" false Boolean 用來設定 KeyboardEvent.isComposing (en-US) 的值
"charCode" 0 unsigned long 用來設定 KeyboardEvent.charCode (en-US) 的值
"keyCode" 0 unsigned long 用來設定 KeyboardEvent.keyCode (en-US) 的值
"which" 0 unsigned long 用來設定 KeyboardEvent.which (en-US) 的值

 KeyboardEventInit dictionary 亦接受 UIEventInitEventInit 所接受的參數。


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! (en-US)

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