Object: KeyboardEvent
The KeyboardEvent object extends the UIEvent object and represents an event generated by the BlackBerry® device keyboard. It provides specific contextual information associated with keyboard devices. Each keyboard event references a key using an identifier. Keyboard events are commonly directed at the element that has the focus.
To create an instance of a KeyboardEvent, you must invoke Document.createEvent() with an input parameter of ”KeyboardEvent”.
KeyboardEvent properties
Property name |
Type |
Description |
Status |
Availability |
|---|---|---|---|---|
altKey |
boolean |
Returns true if the ALT key is pressed or if the ALT key is locked. |
read only |
4.6 or later |
ctrlKey |
boolean |
Returns false. BlackBerry® devices have no CTRL key. |
read only |
4.6 or later |
keyCode |
int |
Returns the key code associated with the key in this event. |
read only |
4.6 or later |
keyIdentifier |
String |
Returns the identifier of the key. |
read only |
4.6 or later |
keyLocation |
int |
Returns a value of DOM_KEY_LOCATION_STANDARD. |
read only |
4.6 or later |
metaKey |
boolean |
Returns false. BlackBerry devices have no Meta key. |
read only |
4.6 or later |
shiftKey |
boolean |
Returns true if the SHIFT key is pressed. |
read only |
4.6 or later |
Keyboard event types
Event type |
Bubbles |
Cancelable |
Description |
|---|---|---|---|
keydown |
yes |
yes |
Occurs when a key is pressed while the pointer is over an element. This event type includes the following context information: KeyboardEvent.altKey, KeyboardEvent.ctrlKey, KeyboardEvent.keyIdentifier, KeyboardEvent.keyLocation, KeyboardEvent.metaKey, KeyboardEvent.shiftKey, UIEvent.view |
keypress |
yes |
yes |
Occurs immediately after a keydown event. This event does not repeat. This event includes the following context information: KeyboardEvent.altKey, KeyboardEvent.ctrlKey, KeyboardEvent.keyIdentifier, KeyboardEvent.keyLocation, KeyboardEvent.metaKey, KeyboardEvent.shiftKey, UIEvent.view |
keyup |
yes |
yes |
Occurs when a key is released while the pointer is over an element. This event type includes the following context information: KeyboardEvent.altKey, KeyboardEvent.ctrlKey, KeyboardEvent.keyIdentifier, KeyboardEvent.keyLocation, KeyboardEvent.metaKey, KeyboardEvent.shiftKey, UIEvent.view |
KeyboardEvent methods
Method: KeyboardEvent.getModifierState()
Method: KeyboardEvent.initKeyboardEvent()
Syntax
KeyboardEvent.initKeyboardEvent( typeArg, canBubbleArg, cancelableArg, viewArg, keyIdentifierArg, keyLocationArg, modifiersList )
Parameters
Parameter |
Type |
Description |
|---|---|---|
typeArg |
String |
Specifies the Keyboard event type. This parameter may have one of the following values: |
canBubbleArg |
boolean |
When true, this parameter indicates that the event can bubble upwards through the DOM tree. This parameter sets the value of Event.bubbles. |
cancelableArg |
boolean |
When true, this parameter indicates that the event’s default action can be cancelled. This parameter sets the value of Event.cancelable. |
viewArg |
AbstractView |
Specifies the window or frame that is generating the event. This parameter sets the value of UIEvent.view. |
keyIdentifierArg |
String |
Specifies the identifier of the key. This parameter sets the value of KeyboardEvent.keyIdentifier. |
keyLocationArg |
String |
Specifies the location of the key on the device that started the key event. This parameter must have a value of DOM_KEY_LOCATION_STANDARD. This parameter sets the value of KeyboardEvent.keyLocation. |
keyLocationArg |
String |
Specifies a whitespace-separated list of modifier key identifiers to be activated on the object. |
Method: KeyboardEvent.initKeyboardEventNS()
The initKeyboardEventNS() method initializes the value of a KeyboardEvent created by Document.createEvent() with the given namespace URI. This method can only be called before the KeyboardEvent has been dispatched.
Syntax
KeyboardEvent.initKeyboardEventNS( namespaceURI, typeArg, canBubbleArg, cancelableArg, viewArg, keyIdentifierArg, keyLocationArg, modifiersList )
String
Parameters
Parameter |
Type |
Description |
|---|---|---|
namespaceURI |
String |
Specifies a modifier key identifier, such as ALT. |
typeArg |
String |
Specifies the Keyboard event type. This parameter may have one of the following values: |
canBubbleArg |
boolean |
When true, this parameter indicates that the event can bubble upwards through the DOM tree. This parameter sets the value of Event.bubbles. |
cancelableArg |
boolean |
When true, this parameter indicates that the event’s default action can be cancelled. This parameter sets the value of Event.cancelable. |
viewArg |
AbstractView |
Specifies the window or frame that is generating the event. This parameter sets the value of UIEvent.view. |
keyIdentifierArg |
String |
Specifies the identifier of the key. This parameter sets the value of KeyboardEvent.keyIdentifier. |
keyLocationArg |
String |
Specifies the location of the key on the device that started the key event. This parameter sets the value of KeyboardEvent.keyLocation. |
modifiersList |
String |
Specifies a whitespace-separated list of modifier key identifiers to be activated on the object. |