GODPAPER | All Packages | All Classes | Index | Frames No Frames |
KeyboardEvent

Package | starling.events
Class | public class KeyboardEvent
Inheritance | KeyboardEvent Event Object

A KeyboardEvent is dispatched in response to user input through a keyboard.

This is Starling's version of the Flash KeyboardEvent class. It contains the same properties as the Flash equivalent.

To be notified of keyboard events, add an event listener to any display object that is part of your display tree. Starling has no concept of a "Focus" like native Flash.

See also

starling.display.Stage

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | altKey : Boolean [read-only] Indicates whether the Alt key is active on Windows or Linux; indicates whether the Option key is active on Mac OS. | KeyboardEvent
|  | bubbles : Boolean [read-only] Indicates if event will bubble. | Event
|  | charCode : uint [read-only] Contains the character code of the key. | KeyboardEvent
|  | ctrlKey : Boolean [read-only] Indicates whether the Ctrl key is active on Windows or Linux; indicates whether either the Ctrl or the Command key is active on Mac OS. | KeyboardEvent
|  | currentTarget : EventDispatcher [read-only] The object the event is currently bubbling at. | Event
|  | data : Object [read-only] Arbitrary data that is attached to the event. | Event
|  | keyCode : uint [read-only] The key code of the key. | KeyboardEvent
|  | keyLocation : uint [read-only] Indicates the location of the key on the keyboard. | KeyboardEvent
|  | shiftKey : Boolean [read-only] Indicates whether the Shift key modifier is active (true) or inactive (false). | KeyboardEvent
|  | target : EventDispatcher [read-only] The object that dispatched the event. | Event
|  | type : String [read-only] A string that identifies the event. | Event

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | KeyboardEvent(type:String, charCode:uint = 0, keyCode:uint = 0, keyLocation:uint = 0, ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false) Creates a new KeyboardEvent. | KeyboardEvent
|  | isDefaultPrevented():Boolean Checks whether the preventDefault() method has been called on the event. | KeyboardEvent
|  | preventDefault():void Cancels the keyboard event's default behavior. | KeyboardEvent
|  | stopImmediatePropagation():void Prevents any other listeners from receiving the event. | Event
|  | stopPropagation():void Prevents listeners at the next bubble stage from receiving the event. | Event
|  | toString():String Returns a description of the event, containing type and bubble information. | Event

Public Constants
Hide Inherited Public Constants
Show Inherited Public Constants

| Constant | Defined By
--- | --- | ---
|  | ADDED : String = added [static] Event type for a display object that is added to a parent. | Event
|  | ADDED_TO_STAGE : String = addedToStage [static] Event type for a display object that is added to the stage | Event
|  | CANCEL : String = cancel [static] An event type to be utilized in custom events. | Event
|  | CHANGE : String = change [static] An event type to be utilized in custom events. | Event
|  | CLOSE : String = close [static] An event type to be utilized in custom events. | Event
|  | COMPLETE : String = complete [static] Event type that may be used whenever something finishes. | Event
|  | CONTEXT3D_CREATE : String = context3DCreate [static] Event type for a (re)created stage3D rendering context. | Event
|  | ENTER_FRAME : String = enterFrame [static] Event type for a display object that is entering a new frame. | Event
|  | FLATTEN : String = flatten [static] Event type for a display object that is being flattened. | Event
|  | KEY_DOWN : String = keyDown [static] Event type for a key that was pressed. | KeyboardEvent
|  | KEY_UP : String = keyUp [static] Event type for a key that was released. | KeyboardEvent
|  | OPEN : String = open [static] An event type to be utilized in custom events. | Event
|  | REMOVED : String = removed [static] Event type for a display object that is removed from its parent. | Event
|  | REMOVED_FROM_STAGE : String = removedFromStage [static] Event type for a display object that is removed from the stage. | Event
|  | REMOVE_FROM_JUGGLER : String = removeFromJuggler [static] Event type for an animated object that requests to be removed from the juggler. | Event
|  | RESIZE : String = resize [static] Event type for a resized Flash Player. | Event
|  | ROOT_CREATED : String = rootCreated [static] Event type that indicates that the root DisplayObject has been created. | Event
|  | SCROLL : String = scroll [static] An event type to be utilized in custom events. | Event
|  | SELECT : String = select [static] An event type to be utilized in custom events. | Event
|  | TEXTURES_RESTORED : String = texturesRestored [static] Event type that is dispatched by the AssetManager after a context loss. | Event
|  | TRIGGERED : String = triggered [static] Event type for a triggered button. | Event

Property Detail

altKey | property

`altKey:Boolean` [read-only]

Indicates whether the Alt key is active on Windows or Linux; indicates whether the Option key is active on Mac OS.

Implementation
`public function get altKey():Boolean`

charCode | property |

`charCode:uint` [read-only]

Contains the character code of the key.

Implementation
`public function get charCode():uint`

ctrlKey | property |

`ctrlKey:Boolean` [read-only]

Indicates whether the Ctrl key is active on Windows or Linux; indicates whether either the Ctrl or the Command key is active on Mac OS.

Implementation
`public function get ctrlKey():Boolean`

keyCode | property |

`keyCode:uint` [read-only]

The key code of the key.

Implementation
`public function get keyCode():uint`

keyLocation | property |

`keyLocation:uint` [read-only]

Indicates the location of the key on the keyboard. This is useful for differentiating keys that appear more than once on a keyboard.

Implementation
`public function get keyLocation():uint`

See also

Keylocation

shiftKey | property |

`shiftKey:Boolean` [read-only]

Indicates whether the Shift key modifier is active (true) or inactive (false).

Implementation
`public function get shiftKey():Boolean`
Constructor Detail

KeyboardEvent | () | Constructor

`public function KeyboardEvent(type:String, charCode:uint = 0, keyCode:uint = 0, keyLocation:uint = 0, ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false)`

Creates a new KeyboardEvent.

Parameters

| `type:String`
| `charCode:uint` (default = `0`)``
| `keyCode:uint` (default = `0`)``
| `keyLocation:uint` (default = `0`)``
| `ctrlKey:Boolean` (default = `false`)``
| `altKey:Boolean` (default = `false`)``
| `shiftKey:Boolean` (default = `false`)``

Method Detail

isDefaultPrevented | () | method

`public function isDefaultPrevented():Boolean`

Checks whether the preventDefault() method has been called on the event.

Returns

| `Boolean`

preventDefault | () | method |

`public function preventDefault():void`

Cancels the keyboard event's default behavior. This will be forwarded to the native flash KeyboardEvent.

Constant Detail

KEY_DOWN | Constant

`public static const KEY_DOWN:String = keyDown`

Event type for a key that was pressed.

KEY_UP | Constant |

`public static const KEY_UP:String = keyUp`

Event type for a key that was released.

Thu Jan 16 2014, 01:11 PM +08:00