KeyEvent class

A custom KeyboardEvent that attempts to eliminate cross-browser inconsistencies, and also provide both keyCode and charCode information for all key events (when such information can be determined).

KeyEvent tries to provide a higher level, more polished keyboard event information on top of the "raw" KeyboardEvent.

The mechanics of using KeyEvents is a little different from the underlying KeyboardEvent. To use KeyEvents, you need to create a stream and then add KeyEvents to the stream, rather than using the EventTarget.dispatchEvent. Here's an example usage:

// Initialize a stream for the KeyEvents:
var stream = KeyEvent.keyPressEvent.forTarget(document.body);
// Start listening to the stream of KeyEvents.
stream.listen((keyEvent) =>
    window.console.log('KeyPress event detected ${keyEvent.charCode}'));
...
// Add a new KeyEvent of someone pressing the 'A' key to the stream so
// listeners can know a KeyEvent happened.
stream.add(new KeyEvent('keypress', keyCode: 65, charCode: 97));

This class is very much a work in progress, and we'd love to get information on how we can make this class work with as many international keyboards as possible. Bugs welcome!

Implements
Annotations
  • @Experimental()

Static Properties

keyDownEventEventStreamProvider<KeyEvent>
read / write

Accessor to provide a stream of KeyEvents on the desired target.

keyPressEventEventStreamProvider<KeyEvent>
read / write

Accessor to provide a stream of KeyEvents on the desired target.

keyUpEventEventStreamProvider<KeyEvent>
read / write

Accessor to provide a stream of KeyEvents on the desired target.

Constructors

KeyEvent(String type, { Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0, int charCode: 0, int keyLocation: 1, bool ctrlKey: false, bool altKey: false, bool shiftKey: false, bool metaKey: false, EventTarget currentTarget })
factory

Programmatically create a new KeyEvent (and KeyboardEvent).

KeyEvent.wrap(KeyboardEvent parent)

Construct a KeyEvent with parent as the event we're emulating.

Properties

altKeybool
read-only

Calculated value of whether the alt key is pressed is for this event.

charCodeint
read-only

Calculated value of what the estimated charCode is for this event.

ctrlKeybool
read-only

True if the ctrl key is pressed during this event.

currentTargetEventTarget
read-only

The currently registered target for this event.

detailint
read-only
keyCodeint
read-only

Calculated value of what the estimated keyCode is for this event.

keyLocationint
read-only

Accessor to the part of the keyboard that the key was pressed from (one of KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK).

locationint
@Experimental(), read-only
metaKeybool
read-only

True if the Meta (or Mac command) key is pressed during this event.

repeatbool
@Experimental(), read-only
shiftKeybool
read-only

True if the shift key was pressed during this event.

sourceCapabilitiesInputDeviceCapabilities
final
viewWindow
read-only
whichint
read-only

Calculated value of what the estimated keyCode is for this event.

bubblesbool
read-only, inherited
cancelablebool
read-only, inherited
codeString
@DocsEditable(), @DomName('KeyboardEvent.code'), @Experimental(), read-only, inherited
defaultPreventedbool
read-only, inherited
eventPhaseint
read-only, inherited
hashCodeint
read-only, inherited

The hash code for this object.

isTrustedbool
read-only, inherited
keyString
@DocsEditable(), @DomName('KeyboardEvent.key'), @Experimental(), read-only, inherited
matchingTargetElement
read-only, inherited

A pointer to the element whose CSS selector matched within which an event was fired. If this Event was not associated with any Event delegation, accessing this value will throw an UnsupportedError.

pathList<Node>
@Experimental(), read-only, inherited

This event's path, taking into account shadow DOM.

runtimeTypeType
read-only, inherited

A representation of the runtime type of the object.

scopedbool
read-only, inherited
targetEventTarget
read-only, inherited
timeStampdouble
read-only, inherited
typeString
read-only, inherited
wrappedEvent
final, inherited

Needed because KeyboardEvent is implements.

Operators

operator ==(other) → bool
inherited

The equality operator.

Methods

getModifierState(String keyArgument) → bool
@Experimental()
deepPath() → List<EventTarget>
inherited
noSuchMethod(Invocation invocation) → dynamic
inherited

Invoked when a non-existent method or property is accessed.

preventDefault() → void
inherited
stopImmediatePropagation() → void
inherited
stopPropagation() → void
inherited
toString() → String
inherited

Returns a string representation of this object.

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-html/KeyEvent-class.html