Packagestarling.events
Classpublic class KeyboardEvent
InheritanceKeyboardEvent Inheritance Event Inheritance 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
 PropertyDefined 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
 Inheritedbubbles : 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
 InheritedcurrentTarget : EventDispatcher
[read-only] The object the event is currently bubbling at.
Event
 Inheriteddata : 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
 Inheritedtarget : EventDispatcher
[read-only] The object that dispatched the event.
Event
 Inheritedtype : String
[read-only] A string that identifies the event.
Event
Public Methods
 MethodDefined 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
  
Checks whether the preventDefault() method has been called on the event.
KeyboardEvent
  
Cancels the keyboard event's default behavior.
KeyboardEvent
 Inherited
Prevents any other listeners from receiving the event.
Event
 Inherited
Prevents listeners at the next bubble stage from receiving the event.
Event
 Inherited
toString():String
Returns a description of the event, containing type and bubble information.
Event
Public Constants
 ConstantDefined By
 InheritedADDED : String = added
[static] Event type for a display object that is added to a parent.
Event
 InheritedADDED_TO_STAGE : String = addedToStage
[static] Event type for a display object that is added to the stage
Event
 InheritedCANCEL : String = cancel
[static] An event type to be utilized in custom events.
Event
 InheritedCHANGE : String = change
[static] An event type to be utilized in custom events.
Event
 InheritedCLOSE : String = close
[static] An event type to be utilized in custom events.
Event
 InheritedCOMPLETE : String = complete
[static] Event type that may be used whenever something finishes.
Event
 InheritedCONTEXT3D_CREATE : String = context3DCreate
[static] Event type for a (re)created stage3D rendering context.
Event
 InheritedENTER_FRAME : String = enterFrame
[static] Event type for a display object that is entering a new frame.
Event
 InheritedFATAL_ERROR : String = fatalError
[static] Event type that is dispatched by the Starling instance when it encounters a problem from which it cannot recover, e.g.
Event
 InheritedIO_ERROR : String = ioError
[static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded.
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
 InheritedOPEN : String = open
[static] An event type to be utilized in custom events.
Event
 InheritedPARSE_ERROR : String = parseError
[static] Event type that is dispatched by the AssetManager when an xml or json file couldn't be parsed.
Event
 InheritedREADY : String = ready
[static] An event type to be utilized in custom events.
Event
 InheritedREMOVED : String = removed
[static] Event type for a display object that is removed from its parent.
Event
 InheritedREMOVED_FROM_STAGE : String = removedFromStage
[static] Event type for a display object that is removed from the stage.
Event
 InheritedREMOVE_FROM_JUGGLER : String = removeFromJuggler
[static] Event type for an animated object that requests to be removed from the juggler.
Event
 InheritedRENDER : String = render
[static] Event type that is dispatched by the Starling instance directly before rendering.
Event
 InheritedRESIZE : String = resize
[static] Event type for a resized Flash Player.
Event
 InheritedROOT_CREATED : String = rootCreated
[static] Event type that indicates that the root DisplayObject has been created.
Event
 InheritedSCROLL : String = scroll
[static] An event type to be utilized in custom events.
Event
 InheritedSECURITY_ERROR : String = securityError
[static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded.
Event
 InheritedSELECT : String = select
[static] An event type to be utilized in custom events.
Event
 InheritedTEXTURES_RESTORED : String = texturesRestored
[static] Event type that is dispatched by the AssetManager after a context loss.
Event
 InheritedTRIGGERED : String = triggered
[static] Event type for a triggered button.
Event
 InheritedUPDATE : String = update
[static] An event type to be utilized in custom events.
Event
Property Detail
altKeyproperty
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
charCodeproperty 
charCode:uint  [read-only]

Contains the character code of the key.


Implementation
    public function get charCode():uint
ctrlKeyproperty 
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
keyCodeproperty 
keyCode:uint  [read-only]

The key code of the key.


Implementation
    public function get keyCode():uint
keyLocationproperty 
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
shiftKeyproperty 
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_DOWNConstant
public static const KEY_DOWN:String = keyDown

Event type for a key that was pressed.

KEY_UPConstant 
public static const KEY_UP:String = keyUp

Event type for a key that was released.