1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
---
title: KeyboardEvent
slug: Web/API/KeyboardEvent
tags:
- 待翻譯
translation_of: Web/API/KeyboardEvent
---
<p>{{APIRef("DOM Events")}}</p>
<p><strong><code>KeyboardEvent</code></strong> objects 用來詳述使用者和網頁之間,經由鍵盤產生的互動。每個事件(<code>event</code>)都記錄著一次鍵盤動作。事件類型(<code>keydown</code> 、 <code>keypress</code> 和 <code>keyup</code>)用來表示鍵盤執行哪種動作。</p>
<div class="note"><strong>注意:</strong> <code>KeyboardEvent</code> 僅顯示在鍵盤上發生的事。當你需要進行文字輸入的操作,請使用 HTML5 <code><a href="/en-US/docs/DOM/DOM_event_reference/input" rel="custom">input</a></code> event 代替 <code>KeyboardEvent</code> 。舉例來說,當使用者在手寫系統,例如平板電腦,輸入文字時,並不會啟動 key events 。</div>
<h2 id="Constructor">Constructor</h2>
<dl>
<dt>{{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}}</dt>
<dd>建立一 <code>KeyboardEvent</code> object。</dd>
</dl>
<h2 id="Methods">Methods</h2>
<p><em>本介面( interface)亦繼承其父, {{domxref("UIEvent")}} 和 {{domxref("Event")}} ,的 methods</em></p>
<dl>
<dt>{{domxref("KeyboardEvent.getModifierState()")}}</dt>
<dd>回傳一 {{jsxref("Boolean")}}。用來表示當事件建立時,修飾鍵(例如 <kbd>Alt</kbd>、 <kbd>Shift</kbd>、 <kbd>Ctrl</kbd>、或是 <kbd>Meta</kbd>) 是否是按下的。</dd>
<dt>{{domxref("KeyboardEvent.initKeyEvent()")}}{{deprecated_inline}}</dt>
<dd>初始化一個 <code>KeyboardEvent</code> object。這個 method 只有 Gecko 有在使用(其他瀏覽器是使用 {{domxref("KeyboardEvent.initKeyboardEvent()")}}),並且不應該再繼續使用。現代的標準規範是使用 {{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}} constructor。</dd>
<dt>{{domxref("KeyboardEvent.initKeyboardEvent()")}}{{deprecated_inline}}</dt>
<dd>初始化一個 <code>KeyboardEvent</code> object。 Gecko 從未實作過該 method (Gecko 是使用 {{domxref("KeyboardEvent.initKeyEvent()")}}) ,並且不應該再繼續使用。現代的標準規範是使用 {{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}} constructor。</dd>
</dl>
<h2 id="Properties">Properties</h2>
<p><em>本介面( interface)亦繼承其父,{{domxref("UIEvent")}} 和 {{domxref("Event")}} ,的 properties 。</em></p>
<dl>
<dt>{{domxref("KeyboardEvent.altKey")}} {{Readonlyinline}}</dt>
<dd>一個 {{jsxref("Boolean")}} 。用來表示在事件建立時, <kbd>Alt</kbd> (OS X 中是 <kbd>Option</kbd> 或 <kbd>⌥</kbd> ) 鍵是否執行中。</dd>
<dt>{{domxref("KeyboardEvent.char")}} {{Non-standard_inline}}{{Deprecated_inline}}{{Readonlyinline}}</dt>
<dd>一個 {{domxref("DOMString")}} ,返回鍵盤對應的字符。若是該鍵對應一個實際的字符,則其值為對應該字符的一個非空的 Unicode 字串;若沒對應的話,則返回一個空字串。
<div class="note"><strong>Note:</strong> If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.</div>
<div class="warning"><strong>警告:</strong> 在 DOM Level 3 Events ,該 propertie 已被移除。現在只有 IE9+ 支持它。</div>
</dd>
<dt>{{domxref("KeyboardEvent.charCode")}} {{Deprecated_inline}}{{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Number")}} representing the Unicode reference number of the key; this attribute is used only by the <code>keypress</code> event. For keys whose <code>char</code> attribute contains multiple characters, this is the Unicode value of the first character in that attribute. In Firefox 26 this returns codes for printable characters.
<div class="warning"><strong>警告:</strong> 此 attribute 已被淘汰。如果可以,建議使用 {{domxref("KeyboardEvent.key")}} 。</div>
</dd>
<dt>{{domxref("KeyboardEvent.code")}} {{Readonlyinline}}</dt>
<dd>一個 {{domxref("DOMString")}} 。返回事件對應的按鍵的代碼。</dd>
<dt>{{domxref("KeyboardEvent.ctrlKey")}} {{Readonlyinline}}</dt>
<dd>一個 {{jsxref("Boolean")}} 。用來表示在事件建立時, <kbd>Ctrl</kbd> 鍵是否執行中。</dd>
<dt>{{domxref("KeyboardEvent.isComposing")}} {{Readonlyinline}}</dt>
<dd>一個 {{jsxref("Boolean")}} 。用來表示其觸發時間是否在 <code>compositionstart</code> 和 <code>compositionend</code> 之間。</dd>
<dt>{{domxref("KeyboardEvent.key")}} {{Readonlyinline}}</dt>
<dd>一個 {{domxref("DOMString")}} ,用來事件對應的按鍵的值(key value)。</dd>
<dt>{{domxref("KeyboardEvent.keyCode")}} {{deprecated_inline}}{{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Number")}} representing a system and implementation dependent numerical code identifying the unmodified value of the pressed key.
<div class="warning"><strong>警告:</strong> 此 attribute 已被淘汰。如果可以,建議使用{{domxref("KeyboardEvent.key")}} 。</div>
</dd>
<dt>{{domxref("KeyboardEvent.locale")}} {{Readonlyinline}}</dt>
<dd>Returns a {{domxref("DOMString")}} representing a locale string indicating the locale the keyboard is configured for. This may be the empty string if the browser or device doesn't know the keyboard's locale.
<div class="note"><strong>Note:</strong> This does not describe the locale of the data being entered. A user may be using one keyboard layout while typing text in a different language.</div>
</dd>
<dt>{{domxref("KeyboardEvent.location")}}<a> {{Readonlyinline}}</a></dt>
<dd>Returns a {{jsxref("Number")}} representing the location of the key on the keyboard or other input device.</dd>
<dt>{{domxref("KeyboardEvent.metaKey")}} {{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Boolean")}} that is <code>true</code> if the <kbd>Meta</kbd> (on Mac keyboards, the <kbd>⌘ Command</kbd> key; on Windows keyboards, the Windows key (<kbd>⊞</kbd>)) key was active when the key event was generated.</dd>
<dt>{{domxref("KeyboardEvent.repeat")}} {{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Boolean")}} that is <code>true</code> if the key is being held down such that it is automatically repeating.</dd>
<dt>{{domxref("KeyboardEvent.shiftKey")}} {{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Boolean")}} that is <code>true</code> if the <kbd>Shift</kbd> key was active when the key event was generated.</dd>
<dt>{{domxref("KeyboardEvent.which")}} {{deprecated_inline}}{{Readonlyinline}}</dt>
<dd>Returns a {{jsxref("Number")}} representing a system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as <code>keyCode</code>.
<div class="warning"><strong>警告:</strong> 此 attribute 已被淘汰。如果可以,建議使用 {{domxref("KeyboardEvent.key")}} 。</div>
</dd>
</dl>
<h2 id="注意">注意</h2>
<p>KeyboardEvent 有 <code>keydown</code> 、 <code>keypress</code> 、 <code>keyup</code> 三種事件。對大多數的按鍵而言, Gecko 觸發事件的順序如下:</p>
<ol>
<li>當按鍵按下時,會送出 <code>keydown</code> event 。</li>
<li>當按鍵不是特殊鍵( modifier key),例如<kbd>Ctrl</kbd> 、<kbd>Alt</kbd>……等等,會送出 <code>keypress</code> event 。</li>
<li>當按鍵放開時,會送出 <code>keyup</code> event 。</li>
</ol>
<h3 id="特殊狀況">特殊狀況</h3>
<p>某些按鍵,例如 <kbd>Caps Lock</kbd> 、 <kbd>Num Lock</kbd> 和 <kbd>Scroll Lock</kbd> 能切換鍵盤上的 LED 燈。在 Windows 和 Linux 系統上,這些按鍵只會觸發 <code>keydown</code> 和 <code>keyup</code> 事件。但是 Linux 上的 Firefox 12 或更早的版本亦會觸發 <code>keypress</code> 事件。</p>
<p>而在 Mac 電腦則不同, <kbd>Caps Lock</kbd> 只會觸發 <code>keydown</code> 事件;而 <kbd>Num Lock</kbd> 則是只有舊版的 Mac 電腦(2007 或之前的版本)才有,現在的 Mac 即便使用外部鍵盤也不支援 <kbd>Num Lock</kbd> 。雖說舊版的 Mac 電腦支援 <kbd>Num Lock</kbd> 鍵,但 <kbd>Num Lock</kbd> 並不會執行任何 KeyboardEvent;而 Gecko 瀏覽器在特殊情況(外接一個有 <kbd>F14</kbd> 的鍵盤)下能支援 <kbd>Scroll Lock</kbd> ,但是它會產生 <code>keypress</code> 事件。這個異常狀態是個 bug ,詳情可參考 {{bug(602812)}}。</p>
<h3 id="自動迴圈(Auto-Repeat_)的執行">自動迴圈(Auto-Repeat )的執行</h3>
<p>當按鍵按下去不放時,它會開始一個自動迴圈。並導致觸發一系列的相似事件,如下所示:</p>
<ol>
<li><code>keydown</code></li>
<li><code>keypress</code></li>
<li><code>keydown</code></li>
<li><code>keypress</code></li>
<li>(不斷重複,直到使用者放開按鍵)</li>
<li><code>keyup</code></li>
</ol>
<p>在 DOM Level 3 說明書有提及這問題是會發生的。其中所存在的問題如下說明:</p>
<h4 id="部分_GTK_環境,例如_Ubuntu_9.4_,的自動迴圈">部分 GTK 環境,例如 Ubuntu 9.4 ,的自動迴圈</h4>
<p>部分的 GTK-based 環境之中,自動迴圈在發生的過程中會自動觸發電腦本機的 key-up 事件。然而,對 Gecko 而言,並沒有方法可以分辨使用者重複點擊按鍵與自動迴圈(按鍵按住不放)的差異。在這類的環境下,按鍵按住不放會重複執行下列事件:</p>
<ol>
<li><code>keydown</code></li>
<li><code>keypress</code></li>
<li><code>keyup</code></li>
<li><code>keydown</code></li>
<li><code>keypress</code></li>
<li><code>keyup</code></li>
<li>(不斷重複,直到使用者放開按鍵)</li>
<li><code>keyup</code></li>
</ol>
<p>不幸地,在這些環境之下,web content 亦沒有方法告訴使用者重複點擊按鍵與自動迴圈的差異。</p>
<h4 id="Gecko_5.0_以前的自動迴圈">Gecko 5.0 以前的自動迴圈</h4>
<p>Gecko 5.0 {{geckoRelease('5.0')}} 以前,在不同平台上,鍵盤的處理與現在相比較不統一。</p>
<dl>
<dt>Windows</dt>
<dd>自動迴圈的結果與 Gecko 4.0 或更新的版本類似</dd>
<dt>Mac</dt>
<dd>在第一個 keydown 執行後,僅執行 keypress 事件,一直到案件放開(即送出 keyup 事件指令),過程中不會送出任何 keydown 事件。</dd>
<dt>Linux</dt>
<dd>鍵盤事件的執行根據平台不同而有所不同。它有可能表現得像是 Windows 也有可能像 Mac ,這取決於本地的事件模型(native event model)是如何執行的。</dd>
</dl>
<h2 id="範例">範例</h2>
<pre class="brush: js"><!DOCTYPE html>
<html>
<head>
<script>
var metaChar = false;
var exampleKey = 16;
function keyEvent(event) {
var key = event.keyCode || event.which;
var keychar = String.fromCharCode(key);
if (key == exampleKey) {
metaChar = true;
}
if (key != exampleKey) {
if (metaChar) {
alert("Combination of metaKey + " + keychar);
metaChar = false;
} else {
alert("Key pressed " + key);
}
}
}
function metaKeyUp (event) {
var key = event.keyCode || event.which;
if (key == exampleKey) {
metaChar = false;
}
}
</script>
</head>
<body onkeydown="keyEvent(event)" onkeyup="metaKeyUp(event)">
</body>
</html>
</pre>
<h2 id="規格">規格</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('DOM3 Events', '#interface-KeyboardEvent', 'KeyboardEvent')}}</td>
<td>{{Spec2('DOM3 Events')}}</td>
<td>原始定義</td>
</tr>
</tbody>
</table>
<p>The <code>KeyboardEvent</code> interface specification went through numerous draft versions, first under DOM Events Level 2 where it was dropped as no consensus arose, then under DOM Events Level 3. This led to the implementation of non-standard initialization methods, the early DOM Events Level 2 version, {{domxref("KeyboardEvent.initKeyEvent()")}} by Gecko browsers and the early DOM Events Level 3 version, {{domxref("KeyboardEvent.initKeyboardEvent()")}} by others. Both have been superseded by the modern usage of a constructor: {{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}}.</p>
<h2 id="瀏覽器支援度">瀏覽器支援度</h2>
<p>More compatibility data is available on other pages:</p>
<ul>
<li><code>.code</code> :請參考《瀏覽器支援度》的 {{domxref("KeyboardEvent.code")}} 部分。</li>
<li><code>.key</code>:請參考《瀏覽器支援度》的 {{domxref("KeyboardEvent.key")}} 部分。</li>
<li><code>.getModifierState()</code> :請參考《瀏覽器支援度》的 {{domxref("KeyboardEvent.getModifierState")}} 部分。</li>
</ul>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td>constructor</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("31.0")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.char</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.charCode</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>.code</code></td>
<td colspan="5" rowspan="1">See Browser compatibility of {{domxref("KeyboardEvent.code")}}.</td>
</tr>
<tr>
<td><code>.isComposing</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatGeckoDesktop("31.0")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.key</code></td>
<td colspan="5" rowspan="1">See Browser compatibility of {{domxref("KeyboardEvent.key")}}.</td>
</tr>
<tr>
<td><code>.keyCode</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>.locale</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.location</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("15.0")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.repeat</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("28.0")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.which</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>.getModifierState()</code></td>
<td colspan="5" rowspan="1">See Browser compatibility of {{domxref("KeyboardEvent.getModifierState")}}</td>
</tr>
<tr>
<td><code>.initKeyboardEvent()</code></td>
<td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
<td>{{CompatNo}}<sup>[2]</sup></td>
<td>{{CompatIE("9.0")}}<sup>[3]</sup></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>constructor</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatGeckoMobile("31.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.char</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.charCode</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.code</code></td>
<td colspan="5" rowspan="1">See Browser compatibility of {{domxref("KeyboardEvent.code")}}.</td>
</tr>
<tr>
<td><code>.isComposing</code></td>
<td>{{CompatNo}}</td>
<td>{{CompatGeckoMobile("31.0")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td><code>.key</code></td>
<td colspan="6">See Browser compatibility table of {{domxref("KeyboardEvent.key")}}.</td>
</tr>
<tr>
<td><code>.keyCode</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.locale</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.location</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatGeckoMobile("15.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.repeat</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatGeckoMobile("28.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.which</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td><code>.getModifierState()</code></td>
<td colspan="5" rowspan="1">See Browser compatibility of {{domxref("KeyboardEvent.getModifierState")}}</td>
</tr>
<tr>
<td><code>.initKeyboardEvent()</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] The arguments of <code>initKeyboardEvent()</code> of WebKit and Blink's are different from the definition in DOM Level 3 Events. The method is: <code>initKeyboardEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString keyIndentifierArg, in number locationArg, in boolean ctrlKeyArg, in boolean altKeyArg, in boolean shiftKeyArg, in boolean metaKeyArg, in boolean altGraphKeyArg)</code></p>
<p>[2] Gecko won't support <code>initKeyboardEvent()</code> because supporting it completely breaks feature detection of web applications. See {{Bug(999645)}}.</p>
<p>[3] The argument of <code>initKeyboardEvent()</code> of IE is different from the definition in DOM Level 3 Events. The method is: <code>initKeyboardEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in views::AbstractView viewArg, in DOMString keyArg, in number locationArg, in DOMString modifierListArg, in boolean repeatArt, in DOMString locationArg)</code>. See <a href="http://msdn.microsoft.com/en-us/library/ie/ff975297%28v=vs.85%29.aspx">document of <code>initKeyboardEvent()</code> in MSDN</a>.</p>
<p><a href="http://www.howtocreate.co.uk/tutorials/javascript/domevents#domevld1">[4]</a> Note that manually firing an event does <em>not</em> generate the default action associated with that event. For example, manually firing a key event does not cause that letter to appear in a focused text input. In the case of UI events, this is important for security reasons, as it prevents scripts from simulating user actions that interact with the browser itself.</p>
|