Help Center

Local Navigation

Object: KeyboardEvent

Availability

BlackBerry® Device Software version 4.6 or later

Extends

UIEvent

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 name

Description

Availability

getModifierState()

Checks the state of a modifier key.

4.6 or later

initKeyboardEvent()

Initializes the value of a KeyboardEvent.

4.6 or later

initKeyboardEventNS()

Initializes the value of a KeyboardEvent with the given namespace URI.

4.6 or later

Method: KeyboardEvent.getModifierState()

Availability

BlackBerry® Device Software version 4.6 or later

The getModifierState() method checks the state of a modifier key.

Syntax

KeyboardEvent.getModifierState( keyIdentifierArg )

Parameters

Parameter

Type

Description

keyIdentifierArg

String

Specifies a modifier key identifier, such as ALT.

Return values

Returns true if the modifier key specified by keyIdentifierArg is activated; otherwise, returns false.

Exceptions

None.

Method: KeyboardEvent.initKeyboardEvent()

Availability

BlackBerry® Device Software version 4.6 or later

The initKeyboardEvent() method initializes the value of a KeyboardEvent created by Document.createEvent(). This method can only be called before the KeyboardEvent has been dispatched.

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.

Return values

None.

Exceptions

None.

Method: KeyboardEvent.initKeyboardEventNS()

Availability

BlackBerry® Device Software version 4.6 or later

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.

Return values

None.

Exceptions

None.

Next topic: Object: Location

Was this information helpful? Send us your comments.