DOM:event.initKeyEvent
From MDC
Contents |
[edit] Summary
The initKeyEvent method is used to initialize the value of an event created using document.createEvent("KeyboardEvent").
[edit] Syntax
event.initKeyEvent (type, bubbles, cancelable, viewArg,
ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
keyCodeArg, charCodeArg)
type- The type of event.
bubbles- A boolean indicating whether the event should bubble up through the event chain or not (see bubbles).
cancelable- A boolean indicating whether the event can be canceled (see cancelable).
viewArg- Specifies UIEvent.view. This value may be
null. ctrlKeyArg- bool True if the Virtual Key to be generated is a combination of the Ctrl key and other keys
altKeyArg- bool True if the Virtual Key to be generated is a combination of the Alt key and other keys
shiftKeyArg- bool True if the Virtual Key to be generated is a combination of the Shift key and other keys
metaKeyArg- bool True if the Virtual Key to be generated is a combination of the Meta key and other keys
keyCodeArg- unsigned long the virtual key code value of the key which was depressed, otherwise zero
charCodeArg- unsigned long the Unicode character associated with the depressed key otherwise zero
See dom/public/idl/events/nsIDOMKeyEvent.idl for the list of key codes.
[edit] Example
// create a key event
event.initKeyEvent(
"keypress", // in DOMString typeArg,
true, // in boolean canBubbleArg,
true, // in boolean cancelableArg,
null, // in nsIDOMAbstractView viewArg, Specifies UIEvent.view. This value may be null.
false, // in boolean ctrlKeyArg,
false, // in boolean altKeyArg,
false, // in boolean shiftKeyArg,
false, // in boolean metaKeyArg,
9, // in unsigned long keyCodeArg,
0); // in unsigned long charCodeArg);
[edit] Notes
Events initialized in this way must have been created with the document.createEvent("KeyboardEvent") method. initKeyEvent must be called to set the event before it is dispatched.
[edit] Specification
This implementation of keyboard events is based on the key events spec in the early versions of DOM 2 Events, later removed from that spec.
The initKeyEvent is the current Gecko equivalent of the DOM Level 3 Events draft initKeyboardEvent method with the following arguments :
typeArg of type DOMString canBubbleArg of type boolean cancelableArg of type boolean viewArg of type views::AbstractView keyIdentifierArg of type DOMString keyLocationArg of type unsigned long modifiersList of type DOMString);